Hello, I have a few problems with my program. First off, let me tell you what the program is.
The snack bar sells only six different items : a sandwich, chips, pickle, brownie, regular drink, and a large drink. All items are subject to sales tax. Set prices for the products.
The program should repeatedly display the menu below until the sale is totaled. The program should keep a running total of the amount of the sale based on the costs that you place in constants for each of the food items. The running total should be displayed somewhere each the menu is displayed again.
S - Sandwich
C - Chips
P - Pickle
B - Brownie
R - Regular Drink
L - Large Drink
X - Cancel and start over
T - Total the sale
If the sale is canceled, clear your running total and display the menu again. When the sale is totaled, calculate the sales tax based on 7%. Print the final total due on the screen.
You can use your own functions to design a solution to the problem. You are required to use a function to calculate the sales tax. Other use of functions is up to you.
Here is what I have so far, my problems are.. I need help with the while statement, I have no clue what to put for it in order for it to work properly. Second, it is saying $4 instead of $4.00 for sandwich, etc. even though I assigned sandwich to 4.00
Code:
#include <iostream.h>
#include <string.h>
#include <iomanip.h>
double sales_tax(double running_total);
main()
{
double sandwich = 4.00;
double chips = 1.75;
double pickle = 0.50;
double brownie = 1.00;
double regular_drink = 1.25;
double large_drink = 2.00;
double salestax;
double total_sale, running_total = 0;
char answer;
do
{
cout << "Enter what you would like, enter S to order a sandwich, C to order chips, etc.\n";
cout << "Enter X to cancel your sale and start over, and when you're finished ordering enter T to total your sale.\n";
cout << "\n *MENU*\n";
cout << "S - Sandwich: $" << sandwich << '\n';
cout << "C - Chips: $" << chips << '\n';
cout << "P - Pickle: $" << pickle << '\n';
cout << "B - Brownie: $" << brownie << '\n';
cout << "R - Regular drink: $" << regular_drink << '\n';
cout << "L - Large drink: $" << large_drink << '\n';
cout << "X - Cancel sale and start over\n";
cout << "T - Total the sale\n\n";
cout << "Your total so far is $" << running_total << '\n' << '\n';
cin >> answer;
switch(answer)
{
case 'S':
running_total = running_total + sandwich;
break;
case 'C':
running_total = running_total + chips;
break;
case 'P':
running_total = running_total + pickle;
break;
case 'B':
running_total = running_total + brownie;
break;
case 'R':
running_total = running_total + regular_drink;
break;
case 'L':
running_total = running_total + large_drink;
break;
case 'X':
running_total = 0;
break;
case 'T':
running_total = sales_tax(running_total);
break;
default:
answer != 'S', 'C', 'P', 'B', 'R', 'L', 'X', 'T' << '\n';
cout << "\nPlease enter an acceptable choice.\n\n";
break;
}
} while (answer != '0');
system("pause");
return 0;
}
double sales_tax(double running_total)
{
return running_total * 1.07;
}