You have an amount of change such as 41 cents or 72 cents


You have an amount of change (such as 41 cents or 72 cents) and you want to figure out how many quarters, dimes, nickels and pennies that is. Your change will always be an integer value between 0 and 99. You can do this with integer division and the mod operator (%).

For example, consider 72 cents. The process defined below will figure out the correct combination of coins:

- Divide 72 by 25 using integer division to determine the number of quarters (72 / 25 = 2) then use the mod function 72 % 25 to see how much change is left (72 % 25 = 22)

- Take the 22 (what you have left) and figure out how many dimes that is (22 / 10 = 2) then use the mod function to see how much change is left (22 % 10 = 2)

- Take the 2 (what you have left) and figure out how many nickels that is (2 / 5 = 0) then use the mod function to see how much change is left (2 % 5 = 2)

- Take the 2 (what you have left) and that is your pennies - Print the number of quarters (2), dimes (2), nickels (0) and pennies (2)

Solution Preview :

Prepared by a verified Expert
JAVA Programming: You have an amount of change such as 41 cents or 72 cents
Reference No:- TGS01522122

Now Priced at $10 (50% Discount)

Recommended (90%)

Rated (4.3/5)