Creating a simple change counting program in C++ (example: enter a money amount less than 100 dollars...and the program will make change, telling how many tens, fives, ones, etc.)
I've noticed that when dividing the number by 1 in order to derive the number of ones, I get a repeating decimal amount, such as infinite precision is not there with a float (binary, base 2 instead of base 10, is the cause, I'm assuming).
How can I fix this problem? Basically, when I perform this operation:
1.12 - 1 = .1199999999
This may seem confusing so here's the code I'm working on...
// begin ones routine
int ones;
ones = money / 1; /* int money to remove decimal */
// substr and setw on next cout for formatting and doesn't pertain to my problem
cout << ones << setw(8) << " ones" << " " << setw(0)
<< bars.substr(0,ones) << endl;
money = money - ones; /* subtract ones from total*/




Reply With Quote