- #1
NDiggity
- 54
- 0
Homework Statement
(Programming) A customer brings purchases worth less than $20 to the till, and hands over a $20 bill. Write a program that prompts a user for the purchase total, then figures out what change the customer should receive -- i.e., how many $10 bills, how many $5 bills, how many toonies ($2), loonies ($1), quarters (0.25), dimes (0.10), nickels (0.05), and pennies (0.01).
The Attempt at a Solution
My only problem is with the pennies part. Here is what I have:
while (change > 0.00) {
change = change - .01;
numberOfPennies = numberOfPennies + 1.;
}
My problem is, let's say the purchases are 19.99. So the change is .01. So my program says how many pennies they should get back. The problem is it says 2. If the purchase is 19.98, it says 3 pennies. What am I doing wrong?