Practice Editing and Compiling
Uncle Bob knows that you have been taking computer science classes and wants you to design a program for his small-town grocery store. He doesn't use bar codes and fancy equipment. He just wants to be able to input a cost for an item and whether or not both the taxes are applied to it.
He wants the values to be stored so that they can be printed out later. He has drawn up his idea of what he thinks his input and output should look like:
cost? 7.70
tax? (y/n) y
cost? 5.23
tax? (y/n) n
cost? 8.90
tax? (y/n) y
cost? 11.21
tax? (y/n) y
cost? 6.32
tax? (y/n) n
For your review, here are your values:
Cost Tax
7.70 0.77
5.23 0.00
8.90 0.89
11.21 1.12
6.32 0.00
------------------
39.36 2.78
Your total bill is: 42.14
Your task is to implement Uncle Bob's idea. To keep things simple, you can assume that each "customer" will have five items, and that the "teller" will never make a mistake typing. (O.K, these are pretty unbelievable, but we are trying to keep it simple)
Your cousin, Brittany, tried to write the code, but she made
six mistakes. If you want to start with
her code, you can use the repl link given for this lab.
A couple of CS110 labs might come in handy:
Remember the commands that you need to compile and run C++ code.
If you would like, an algorithm is provided here
- Declare two arrays: one for cost and one for tax
- Declare additional variables such as letter input (for y or n), and totals for cost and tax.
- Loop five times
- prompt for cost
- input the cost into the array
- prompt for y and n
- input the y and n
- if the letter is y, then store the tax (cost * .10) into the tax array, otherwise, set the tax array value to 0
- Print some headers (such as " Cost Tax ")
- Loop five times
- print the cost and the tax
- add the current cost (in the array) to a total
- add the current tax (in the array) to a total
- Print the cost total and the tax total
- Print the total bill