187k views
3 votes
Question 6)

Write the pseudocode and a program that asks the user to provide the amount of change in cents. Calculate how many coins (quarters, dimes, nickels and pennies) must be given back to the client so that they have the LEAST amount of coins. For example,

if the change is 43 cents, the client should receive:

1 quarter(s), 1 dime(s), 1 nickel(s), 3 pennies.

If the change is 289 cents, the client should receive:

11 quarter(s), 1 dime(s), 0 nickel(s), 4 pennies

What will be the amount of change if the total change is 342 cents?

1 Answer

5 votes

Final answer:

To make 342 cents, a client should receive 13 quarters, 1 dime, 1 nickel, and 2 pennies using the least number of coins possible.

Step-by-step explanation:

To determine how many coins of each denomination are required to make up a total change of 342 cents, one can apply a greedy algorithm that starts with the highest denomination and works down to the smallest.

Step-by-Step Calculation

  1. First, divide the total change by the value of a quarter (25 cents) to get the number of quarters. 342 ÷ 25 = 13 quarters, with a remainder of 17 cents.
  2. Next, divide the remainder by the value of a dime (10 cents) to find the number of dimes. 17 ÷ 10 = 1 dime, with a remainder of 7 cents.
  3. Then, divide the new remainder by the value of a nickel (5 cents) to get the number of nickels. 7 ÷ 5 = 1 nickel, with a remainder of 2 cents.
  4. Lastly, the final remainder is the number of pennies needed. So, 2 cents ÷ 1 = 2 pennies.

Therefore, for a total change of 342 cents, the client should receive 13 quarter(s), 1 dime(s), 1 nickel(s), and 2 pennies.

User Bruce Blackshaw
by
8.5k points