In article <47***********************@news.free.fr>, "Daniel.C" <dc*************@free.frwrote:
>Hello.
I'm a complete beginner and I cant go through the third exercise of my book
;-(((
I wrote :
#include <stdio.h>
main()
{
int fahr;
for (fahr = 300; fahr <= 0; fahr = fahr - 20)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}
There is no output. The reverse (from 0 to 300) is OK.
I'm using MinGW with windows XP.
What's wrong ?
What's wrong is that the second part of a for statement ( fahr <= 0, in this
case) specifies the condition under which the loop is to continue running.
You've told it to start out with fahr = 300, and subtract 20 from it,
continuing for as long as the value of fahr is less than or equal to zero.
Of course, fahr is already greater than zero when you start, so the condition
under which the loop is to continue running is already false from the very
beginning -- and the loop never executes.
It appears to me that you've misunderstood the second part as specifying the
condition under which the loop is to stop. That's not the case.
--
Regards,
Doug Miller (alphageek at milmac dot com)
It's time to throw all their damned tea in the harbor again.