float  coins;

printf ("please pick an positive number\n");    

coins = GetFloat();

 while (  coins <    0.01    );      

 printf("%f", coins );

It does work as intended for .01001 and greater. (The idea is to find numbers greater than a certain value, so the test is correct as far as the "<" goes. The intent is to loop when the value is not valid - it's called checking for unwanted data.)

The problem is related to how floating point numbers are stored, the whole point of the exercise. If you were to printf the value stored in coins when .01 is entered to 25 or more digits, you'd see that the value is actually something like 0.00999999977648258209228515625 Because it is only printed to about 8 digits by default, it is rounded at that point and the trailing 0s are not printed. It would print as 0.01, but it is still actually less than .01, so the loop continues.


because ur condition is coins<0.01 so when coins is greater or equal to 0.01 the condition is false the loop exits...so think about it ..vote if u understood..happy codeing

  • This doesn't explain what's really happening and it appears that the answer doesn't get that the loop is only supposed to repeat when unwanted values are entered in order to get correct values. (It needs to be answered within the context of pset1 and the greedy program.)
    – Cliff B
    Apr 26 '17 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .