Re: Basic C++ Calculator Works only 99.5% of Time
Originally Posted by
tony flury
if you want to definitely avoid rounding errors - don't read into a double at all - you technique of multiplying by 100 may solve the one test case you have but there might be others that you still get bitten by.
I would read the input into a string buffer, and then parse that directly into an integer - and do validation at the same time if you want.
That way your ammounts never go anywhere near a double, and no rounding errors will bite you.
+1
Posting code? Use the [code] or [php] tags.
I don't care, I'm still free. You can't take the sky from me.
Bookmarks