To gain experience writing programs which take input, perform calculations and output results.
For this lab, you'll be creating a program that could be used for workers at a snack bar. The snack bar sells 4 items at different prices:
|Bottles of water||.50|
|Bags of popcorn||0.25|
|Cans of soda||0.75|
Your program will help the snack bar workers by figuring out the total cost of all items that a customer wants to purchase. It will ask how many items of each type the customer has selected, calculate the total, and print it to the screen.
For example, if someone purchases 2 bottles of water, 4 candy bars, 4 bags of popcorn and 2 cans of soda, the program should calculate their total cost as $7.50.
Your program should work for any number of items that the user selects. Of course you can't test every possible input, but you should test with several different ones.
Below are a couple of example runs you can try out. The answers that the user gives are given in bold face:
How many bottles of water? 2 How many candy bars? 4 How many bags of popcorn? 4 How many cans of soda? 2 The total cost is 7.5
How many bottles of water? 1 How many candy bars? 2 How many bags of popcorn? 3 How many cans of soda? 4 The total cost is 6.25
How many bottles of water? 100 How many candy bars? 0 How many bags of popcorn? 0 How many cans of soda? 1 The total cost is 50.75
Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.