"Bo" <> wrote in message
news: om...
> Actually, supposedly, a, b are double:
>
> for( int i=0, double a=0.0, double b=0.0 ; i<100; a+=0.1, b+=0.2 )
>
> Do you mean a, b are automatically converted to int because they were
> declared after "int i=0,"? (notice the comma)
VC++ seems to be (strangely) ignoring "double", which is illegal in that
context. You can't define two different types of variable in the first bit
of a for loop. In other words, these are ok (if rather pointless, since they
don't do anything in these examples

):
for(int i=0; i<10; ++i) {}
for(double d=0; d<10; d+=0.1) {}
but what you had above isn't.
What VC++ is doing is treating what you wrote as if you'd written this:
for(int i=0, a=0.0, b=0.0; i<100; a+=0.1, b+=0.2)
> Sorry for introducing the line printf("%s\n", i+a+b). As I said my
> original code is too complicated so I just used this line without much
> thought. Regardless of its erraneous syntax, I still don't see the for
> loop prob.
Hopefully the above clarified things a bit? Incidentally, the syntax of the
printf line isn't the problem, it's its semantics. In other words, it will
compile, but it still won't work.
HTH,
Stuart.
P.S. Apologies for taking a bit of a swipe at you in my original posting
about not reading the compiler warning (looking back at my post, it didn't
come across as entirely friendly

) The advice about reading warnings is
worth noting, nonetheless, you can catch a number of bugs that way (and
avoid spending lots of time debugging).
> Thanks.
>
>
> > ?
> >
> > Just out of curiosity...
> >
> > FWIW, the reason the values never increase is that a and b are both of
type
> > int. If you add 0.1 to an int, what do you get? The same int back again,
> > hence the problem you're experiencing.
> >
> > > This works, however:
> > >
> > > double a=0.0, b=0.0;
> > >
> > > for( int i=0 ; i<100; a+=0.1, b+=0.2 )
> > > {
> > > printf( "%s\n", i+a+b );
> > > }
> >
> > It should do.
> >
> > > I used visual c++ 6.0
> > >
> > > Damn it took me four hours to catch this. Of course, my original code
> > > is whole lot more complicated.
> >
> > And the moral of this story is: read compiler warnings, understand them,
and
> > act on them. If you can't find the bugs your compiler is telling you
about,
> > you'll never find the really nasty, obscure ones. The warnings are there
for
> > a reason (well, except the one about truncation of long identifiers in
the
> > debugger, which is a really pointless warning).
> >
> > > Is there a way to print text to a console window even if your project
> > > is "win32 application"?
> >
> > Yes. It's entirely off-topic in a C++ language newsgroup, however. You
want
> > to ask this in microsoft.public.vc.language. FWIW:
> >
> > <OT>
> > Look up "CreateConsoleScreenBuffer" in MSDN and check out the related
> > "Console Functions" (link at the bottom of the page).
> > </OT>
> >
> > HTH,
> >
> > Stuart.