Have you ever been in a sweet shop to buy sweets? For this challenge we are going to spend £5 in a sweet shop hence we need to find out how many sweets we can afford. We will want to pick and mix sweets until we have spent all our money.
To help us buy our sweets we are going to write a program that will help us decide how many sweets we can afford while allowing us to pick and mix different types of sweets.
Here are the sweets available in the shop:
Here are the main steps of our program which will:
- Display a price list of all the sweets available in the shop,
- Ask the end-user how much they would like to spend,
- Ask the user which sweet they would like to buy and how many of them they would like (A to E),
- Allow the user to enter X (instead of the A to E letter for a sweet) to stop buying more sweets,
- Check whether the use can afford these and if they can, calculate and display how much money they have left,
- Repeat steps 3 to 5 for as long as the user has some money left.
Now let’s see how a flowchart can help us describe these steps further:
Your task:
Use the above flowchart to complete the code below:
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area