I have this small C program and I am unable to locate the mistake. Can someone help me locate it?
The program is supposed to print "Condition is not satisfired", but instead the program gives "HELLO:b is greater than a"
printf("\nHELLO:b is greater than a\n");
printf("\ncondition is not satisfied");
Hope someone can help me locate the error.
Thanks in advance.
You mean other than the fact that you forgot how to indent, and that you've neglected to pay attention to your compiler's warnings?
Oops.. sorry abt that...was in a hurry when I posted that. Will take care next time and indent.
There were no warning given by the compiler. I executed the program on Fedora 1 gcc compiler and there were no warnings or error messages.
Just a recommendation...
alias gcc="gcc -Wall -Wextra -ansi -pedantic"
> Hope someone can help me locate the error.
Yeah, your assumption that floating point numbers are totally accurate is the problem.
Mathematically, you expect a and b to be the same, but in floating point calculations, there is always a small degree of error.
So what you think might be a == b could result in any of these conditions being true
a < b
a == b
a > b
Thanks Salem. It turns out that the assumption was only the problem. When I printed up to 20 digits after the decimal point, I could see the difference in the two numbers.