Just a quick question--is there a way to do an accurate comparison of floating point numbers? Here's an excerpt of the code that I'm working on:
//this while loop will be executed if the user
//enters a negative or zero value as a check
//amount
while( *ptr < 0.01)
{
printf("Please enter a positive amount for the check: "
scanf("%f", ptr);
getchar();
} //end of while loop
Unfortunately, when '0.01' is entered, I go into the while loop. I know that 1/100 cannot be accurately represented in binary and that this must be what is causing the problem, but does anyone have any a relatively simple way to solve this problem? Thank you.
Carrie
//this while loop will be executed if the user
//enters a negative or zero value as a check
//amount
while( *ptr < 0.01)
{
printf("Please enter a positive amount for the check: "
scanf("%f", ptr);
getchar();
} //end of while loop
Unfortunately, when '0.01' is entered, I go into the while loop. I know that 1/100 cannot be accurately represented in binary and that this must be what is causing the problem, but does anyone have any a relatively simple way to solve this problem? Thank you.
Carrie