This challenge is a basic first step into the change-making problem, which is an interesting topic of research for mathematicians and programmers alike.
For the purpose of this challenge, we will only be dealing with pence. If you want to make this more challenging, you can use pound coins and notes too.
Write a program which asks the user to enter the price of a customer’s shopping bill (In pence). It should then also ask the user to enter the amount of cash the customer has handed over (In pence). The program will then calculate and output the correct amount of change to give the customer.
Given the following list of available coins, calculate and output which coins the user will need to give to the customer as change.
[1, 2, 5, 10, 20, 50]
For example: If we have to give 61p of change, we would give the user 50p, 10p and 1p.
There is now a limited quantity of each coin available in the till. The quantity of each coin is stored in a list below.
[20, 4, 5, 3, 1, 3]
(So for example: there are 20 1p coins, 4 2p coins etc.)
Modify your program so that it now tells the user which coins to issue, based on the limited quantity of coins. If there is insufficient change available, then an error message should be displayed.