Hello everyone, I am a intermediate programmer that had done some programming with PHP, ASP, SQL, Fortran, Matlab and VB and now wanting to learn C.

however I am coming through some very awkward problem, the logic is defeating itself.

Code:

#include <stdio.h>
main()
{ double x;
double y;
printf("hello\n");
y = 2.0;
while (y < 100.0)
{
y = y + 0.5;
printf("y = %f\n" y);
/* output statement */
if (y < 100.0)
{
printf("y is less than 100.0 because y is %f\n", y);
}
else
{
printf("y is greater than 100.0 because y is %f\n", y);
}
}
}

output:

y is less than 100.0 because y is 3.000000

y is less than 100.0 because y is 3.500000

y is less than 100.0 because y is 4.000000

y is less than 100.0 because y is 4.500000

y is greater than 100.0 because y is 5.000000

y is greater than 100.0 because y is 5.500000

y is greater than 100.0 because y is 6.000000

y is greater than 100.0 because y is 6.500000

y is greater than 100.0 because y is 7.000000

y is greater than 100.0 because y is 7.500000

y is greater than 100.0 because y is 8.000000

y is greater than 100.0 because y is 8.500000

y is greater than 100.0 because y is 9.000000

Strange thing is, the output statement is outputing the else after y becomes greater than 5.0.

its as simple as, I went into a loop with a specific condition (y < 100), but within the loop, when I use if (y<100), some times the result is true, sometimes its false!!!

I am not sure if it is a compiler problem, a windows problem, a type casting problem or anything, I am scratching my head all over it.

Below is the system and C compiler configuration:

Windows Vista Business SP2 32bit

CPU: Intel Q9500

C compiler: Tiny C compiler 0.9.25 (TCC)

would be grateful if anyone can give any suggestion.