Lookup product description and price.
A touchscreen till displays a number of virtual buttons. Each button corresponds to a product for sale. For example, button 1 is a Snickers Bar. The products are held in a file called `products.txt`. The format of the file is: button number, product name, price.
0,CADBURY DAIRY MILK WHOLENUT 49G,0.70
1,SNICKERS BAR 48G,0.70
2,CADBURY DAIRY MILK MILK CARAMEL,0.70
3,MARS BAR ORIGINAL 51G,0.80
4,CADBURY FLAKE 32G,0.80
5,GALAXY CARAMEL STANDARD 48G,0.80
6,GALAXY MILK CHOCOLATE 46G,0.80
7,CADBURY STAR BAR 49G,0.60
8,NESTLE MUNCHIES 52G,0.60
9,KINDER BUENO 43g,1.00
10,SNICKERS DUO 83.4G,1.00
For the purposes of testing, the till is simulated with the user entering a button number followed by Enter. Pressing Enter without a number simulates the end of a transaction. A user can input any number of products in a single transaction. When a transaction is complete the total price is displayed.
Write a program that allows the user to enter a button number. Invalid numbers are rejected. The program outputs then name of the product and the price. The user can keep entering numbers until they press Enter, at which point the total of the transaction is shown.
Use this boilerplate code as a starting point:
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
Enter button number: 2
CADBURY DAIRY MILK MILK CARAMEL £0.70
Enter button number:
Total: £0.70
Enter button number: -1
Enter button number: 13
Enter button number: a
Enter button number:
Total: £0.00
Enter button number: 8
NESTLE MUNCHIES 52G £0.60
Enter button number: 2
CADBURY DAIRY MILK MILK CARAMEL £0.70
Enter button number: 4
CADBURY FLAKE 32G £0.80
Enter button number:
Total: £2.10
Use these resources as a reference to help you meet the success criteria.
Run the unit tests below to check that your program has met the success criteria.
Enter button number: -1
Enter button number: g
Enter button number: 13
Enter button number:
Total: £0.00
Enter button number: 5
GALAXY CARAMEL STANDARD 48G £0.80
Enter button number: 8
NESTLE MUNCHIES 52G £0.60
Enter button number: 2
CADBURY DAIRY MILK MILK CARAMEL £0.70
Enter button number: 9
KINDER BUENO 43g £1.00
Enter button number:
Total: £3.10
Check that you have: