# Making change

• October 7th, 2011, 01:45 AM
Jerick
Making change
I need to figure out the math for this program.

I have 2 inputs, Amount Owed and Amount Paid. Then from that I get Total Change (Amount Paid - Amount Owed). So if I have 500 Amount Paid and 272 Amount Owed, then Total Change is 228.

Now from that I convert that into dollars, quarters, dimes, nickels, pennies. So 228 would be 2 dollars, 1 quarters, 0 dimes, 0 nickels, 3 pennies. 844 would be 8 dollars, 1 quarters, 1 dimes, 1 nickels, 4 pennies.
• October 7th, 2011, 03:25 AM
luck999
Re: Making change
do not always use changeQuarters

Code :

changeDimes = remainingChange / 10;
remainingChange = remainingChange - changeDimes * 10;

changeNickels = remainingChange / 5;
remainingChange = remainingChange - changeNickels * 5;

changePennies = remainingChange / 1;
remainingChange = remainingChange - changePennies * 1;

• October 7th, 2011, 07:32 AM
kenster421
Re: Making change
If you can take what luck999 has given you and expand that to fit your problem, then you will be in good shape. Remember to go from largest to smallest.
• October 7th, 2011, 06:49 PM
Jerick
Re: Making change
Quote:

Originally Posted by luck999
do not always use changeQuarters

Yeah, that works. Thanks.

I wonder if there's a way to do it with modulus %?