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.
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
read_database that:products.txt file into a 2D list.get_product that:output_product that:transaction that:get_product to input the button number.output_product to output the relevant data.main program so that:read_database.transaction is called.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
Automated feedback for this assignment is still under construction. Submitted programs are checked for syntax errors and their source code is checked for potential errors, bugs, stylistic issues, and suspicious constructs. However, no checks are performed yet to see if the program correctly implements the behaviour specified in the assignment.