Sweet Shop

sweetsHave 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:
sweet-shop-price-list

Here are the main steps of our program which will:

  1. Display a price list of all the sweets available in the shop,
  2. Ask the end-user how much they would like to spend,
  3. Ask the user which sweet they would like to buy and how many of them they would like (A to E),
  4. Allow the user to enter X (instead of the A to E letter for a sweet) to stop buying more sweets,
  5. Check whether the use can afford these and if they can, calculate and display how much money they have left,
  6. 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:
sweet-shop-flowchart

Your task:


Use the above flowchart to complete the code below:

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.2 / 5. Vote count: 11

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,