In Canada, a dollar is made up of 100 cents, and coins come in these values: quarters (25 cents), dimes (10 cents), and nickels (5 cents). A vending machine needs to give a customer their change in coins. The machine always gives change using the fewest coins possible, by handing out the largest coin it can at each step.
The machine also needs to track, across every customer it has ever served, how many total coins it has handed out.
Write a recursive function dispenseChange(int amountInCents) that prints the coins needed to make up the amount, using the fewest coins possible, and returns the number of coins given out.
Write a function, serveCustomer(int amountInCents), that represents one customer being served. It should validate that amountInCents is a multiple of five before calling dispenseChange, and keep a running total of coins given out across every customer served so far, printing that total after each call.
Dispensing change for 40 cents:
Quarter
Dime
Nickel
Total coins dispensed so far: 3
Dispensing change for 65 cents:
Quarter
Quarter
Dime
Nickel
Total coins dispensed so far: 7