Complete the following program to output the exact change with the least number of coins for a given number of cents in integer variable totalCents
The change will be given in quarters (25 cents), dimes (10 cents), nickels (5 cents), pennies (1 cent)
int totalCents = 137;
Output should be
Quarters: 5 Dimes: 1 Nickels: 0 Pennies: 2
How many quarters? 137 / 25 = 5 quarters (Integer Division!)
What’s leftover? 137 % 25 = 12 cents
How many dimes? 12 / 10 = 1 dime
What’s leftover? 12 % 10 = 2 cents
How many nickels? 2 / 5 = 0 nickels.
What’s leftover? 2 % 5 = 2 cents.
How many pennies? 2 / 1 = 2 pennies
int totalCents = 50;
Output should be
Quarters: 2 Dimes: 0 Nickels: 0 Pennies: 0
How many quarters? 50 / 25 = 2 quarters (Integer Division!)
What’s leftover? 50 % 25 = 0 cents
How many dimes? 0 / 10 = 0 dimes
What’s leftover? 0 % 10 = 0 cents
How many nickels? 0 / 5 = 0 nickels.
What’s leftover? 0 % 5 = 0 cents.
How many pennies? 0 / 1 = 0 pennies
int totalCents = 99;
Output should be
Quarters: 3 Dimes: 2 Nickels: 0 Pennies: 4
How many quarters? 99 / 25 = 3 quarters (Integer Division!)
What’s leftover? 99 % 25 = 24 cents
How many dimes? 24 / 10 = 2 dimes
What’s leftover? 24 % 10 = 4 cents
How many nickels? 4 / 5 = 0 nickels.
What’s leftover? 4 % 5 = 4 cents.
How many pennies? 4 / 1 = 4 pennies
Test your solution here
when it passes, copy it and submit it here so your coach can grade it.