This is an example of what you should be able to do at the Introduction to Programming level. If you are not able to do this exercise, you should do one of these courses:

Use 5 arrays to create a shopping cart with 4 items . To represent this we need to:

Define and initialise the following 4 arrays:

Array Names

Initial Values

Items
Descriptions
Prices
Quantities
Totals
[1,2,3,4]
[“Coke”,”Kit Kat”, “Bar One”, “Fanta”]
[7.5, 9.5, 8.5, 7.5]
[0. 0. 0. 0]
[0.0,0,0,0.0,0.0]

 

  • Let the user select some items (1 – 4) and if a selection is already in the array, then increment the corresponding quantity by 1.
  • Re-display the shopping cart after every selection (until next notes), showing the updated quantity and line total.
  • If the user selects an item number (5 or more) which is not in the shopping cart, then nothing is done – at this stage we only want to work with the initial 4 items.
  • If the user enters 99 – then the program quits and prints out the contents of the shopping cart as such:

Item

Description

Price

Quantity

Total

1
2
3
4
Coke
Kit Kat
Bar One
Fanta
R7.50
R9.50
R8.50
R7.50
1
4
2
1
R7.50
R38.00
R17.00
R7.50

 

Grand Total : R70.00

This program tests to see that you are familiar with, and are able to solve problems with arrays, loops, and flow control.

Leave a Comment

Your email address will not be published.