CPSC 120 LAB 7 | Back to Lab index page |
Lab must be completed and reviewed by Peer Instructor Seth Peery no later than Fri, Oct 12 during lab class.
You are to write a nicely documented Ada program that will calculate the bill for customer's at Joe's Candy Bar Store. Joe sells a limited number of candy bars and does a great volume so he keeps the price below his competition. Joe's sells only five types of candy bars: Snickers, Pay Day, Baby Ruth, Milky Way, and Butterfinger. Your computer program should prompt the user to enter a two character code for the type of candy bar the user wants: SN - Snickers, PD - Pay Day, BR - Baby Ruth, MW - Milky Way, and BF - Butterfinger (the user can also enter DN for done). It should then prompt the user for how many candy bars of that type they want. It would then prompt the user again for the type candy bar they want, the user might enter another type or they might enter DN for Done. (Users might enter the same type candy bar more than once during a session.) If the user enters done, the program should calculate the total bill based on the following prices:
Snickers - $0.52, Pay Day - $0.58, Baby Ruth - $0.56, Milky Way - $0.52, and Butterfinger - $0.57.
Next the program should display their order and a bill (as in the following sample). Sales tax is added on at the rate of 4.5% for the number of $ spent, there is no sales tax on orders less than a dollar. So, sales tax on a $5.22 order is calculated 5.22 * 0.045 = $0.23. (Note - sales tax is rounded to the nearest penny.) The total cost on such an order is $5.22 + $0.23 = $5.45. The sales tax should be implemented in your program as a function.
Sample
Program outputs: |
Enter a two character code for the type of candy bar the you want:
|
User inputs: | SN |
Program outputs: | How many Snickers bars do you want? |
User inputs: | 3 |
Program outputs: |
Enter a two character code for the type of candy bar the you want:
|
User inputs: | MW |
Program outputs: | How many Milky Way bars do you want? |
User inputs: | 2 |
Program outputs: |
Enter a two character code for the type of candy bar the you want:
|
User inputs: | SN |
Program outputs: | How many Snickers bars do you want? |
User inputs: | 2 |
Program outputs: |
Enter a two character code for the type of candy bar the you want:
|
User inputs: | PD |
Program outputs: | How many Pay Day bars do you want? |
User inputs: | 3 |
Program outputs: |
Enter a two character code for the type of candy bar the you want:
|
DN | |
Program outputs: |
You ordered: Tax = $0.24 Total Bill = $5.62 |
A basic layout of the program in informal terms --
loop
put prompt for type of candy bar
get type candy bar
exit when type candy bar = DN
put prompt for number they
want
get the number (new order)
if candy bar type = sn then
sncount = sncount + new order
if candy bar type = pd then
pdcount = pdcount + new order
((
similar for the other type bars))
end loop
calculate the total cost of all the orders
sales tax = salestax( )
(this is a function!)
put type bars , cost, sales tax, and total cost