Perhaps you don't understand float imprecision fully enough. If you were to print the value of ch with more digits of precision, you would see what's happening. Try using the following:
This will show a more accurate value of what is in ch, rather than a rounded off value generated by the default precision resulting from the printf statement.
printf defaults to printing floats to about 8 digits of precision. It will round the last digit, the 8th digit, based on what follows. The actual value is stored to about 29 digits of decimal precision. So, for example, 0.009999999999999999 will be printed as 0.01 using the default print precision.
While in the real world, the algorithm above seems like it would work, it completely misses the point of the exercise. The problem with floating point imprecision must be dealt with before executing all of the calculations. Imagine if a bank made this kind of error, just off by a "fraction of a penny." Now, magnify that by thousands of customers and millions of transactions. The accountants would go insane!!! ;-)
Someone at a bank once took advantage of this by programming a tiny fraction of a penny's worth of interest from all the interest calculations each month at a major bank. By transferring these "rounding errors" of about 0.001 cents or less at a time to a separate account, they were able to divert thousands of dollars! Well, until they were caught by an audit. I think there was even a fictional movie made, based on this.
I recommend going back and reviewing the lectures and the walkthrough videos.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)