I have a lab where I am asked to take an amount of money and convert it into the types of bills and coins. We only have an infinite amount of US $20, $5, $1, 50c, 25c, 10c, 5c, and 1c. I started writing the code: the output for the bills is always correct, but sometimes the change is the wrong amount. An example output is below. I think my amount is rounding somewhere in the code. I was informed that float and double and not great when converting money, but I was not sure any other to approach the lab.
Yeah. It's floating point rounding error. You should probably ask the user to input how many dollars they have and how much change they have, then convert it all to an integer value in pennies.
1 2 3 4 5 6 7 8 9
int amountChange, amountCash, pennies;
cout << "Please enter amout of dollars: ";
cin >> amountCash;
cout << "Please enter amount of change: "
cin >> amountChange;
pennies = amountCash * 100 + amountChange;
//figure out bill and change