CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Nov 2008
    Posts
    3

    Error while comparing Float variable

    Dear friends,
    Please take a look at the following code. Its storing .7 to b and comparing b with .7 . But getting just the opposite of expected result!!

    Please explain!

    (Three is expected o/p but we get two when run)

    Code:
    #include<stdio.h>
    int main(int argc,char **argv)
    {
     float a=0.5,b=0.7;
     if(b<0.7)
     {
    	 
    	if(a<0.5)
    	 {
       printf("\nONe");
    	}
         else
    	 {
       printf("\nTwo");
    	 }
     }
     else
     {
      printf("\nThree");
     }
     return 0;
    }
    Last edited by cijothomas; November 30th, 2008 at 10:05 AM. Reason: to <code>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured