View Single Post
Old Mar 20th, 2008, 7:34 AM   #1
Lakrids
Newbie
 
Join Date: Dec 2007
Posts: 28
Rep Power: 0 Lakrids is on a distinguished road
Extremely weird program behavior

Hello,

I have been programming for quite a while now, but the following behavior is one of the most weird ones I ever encountered. It really is annoying me, and I just can't get to the bottom of it. So, in short, the other day I was writing a very small program which calculates all possible solutions to a given problem. The program didn't work, and after some debugging, I was astonished that the following code just doesn't seem to work for some obscure reason. The problem is that nothing is written to the screen in the loop :

cplusplus Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. int main() {
  4.  
  5. for (double C=0.0; C<100.0; C+=0.1)
  6. if (C==1.0)
  7. std::cout << C << std::endl;
  8.  
  9. return 0;
  10. }

The program always evaluates (C==1.0) as false. Why?
Lakrids is offline   Reply With Quote