1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
/**
Assume that user can only order one item from the menu. But use can enter a quantity for the item.
The program displays the items and the item price, the sale tax of 9.25% , and it also asks for a tip amount.
Then it displays the total sales.
All input numbers can not be negative. Display an error message if they are.
The maximum order quantity for item a, b, and c is 50.
The maximum order quantity for the other items is 200.
Display and error if quantity exceeds the limits.
Sample run:
Welcome to the C++ restaurant. You can choose of the following items :
a- Grilled salmon, price $24.99
b- New York Steak, price $17.99
c- Roast Chicken, price $15.99
d- Salad, price $5.99
e- Soup, price $7.99
f- Hamburger, price $4.99
g- Soft drink, price $1.29
h- Tea, price $1.50
i- Orange juice, price $2.50
Enter a letter for the item: a
Enter the quantity: 3
The item price for (3 x Grilled salmon) is: $74.97
The sale tax is $6.93
Enter the gratuity amount: 10.00
Your total price is $91.90
Thank you for your order
*********/
int main()
{
cout << "Welcome to the C++ restaurant. You can choose one of the following items: \n" << endl;
cout << "a- Grilled salmon, price $24.99\n"
<< "b- New York Steak, price $17.99\n"
<< "c- Roast Chicken, price $15.99\n"
<< "d- Salad, price $5.99\n"
<< "e- Soup, price $7.99\n"
<< "f- Hamburger, price $4.99\n"
<< "g- Soft drink, price $1.29\n"
<< "h- Tea, price $1.50\n"
<< "i- Orange juice, price $2.50\n" << endl;
char item;
cout << "Enter a letter for the item: ";
cin >> item;
double price;
string food;
switch(item)
{
case 'a': food = "Grilled Salmon";
price= 24.99;
break;
case 'b': food = "New York Steak";
price= 17.99;
break;
case 'c': food = "Roast Chicken";
price= 15.99;
break;
case 'd': food = "Salad";
price= 5.99;
break;
case 'e': food = "soup";
price= 7.99;
break;
case 'f': food = "Hamburger";
price= 4.99;
break;
case 'g': food = "Soft Drink";
price= 1.29;
break;
case 'h': food = "Tea";
price= 1.50;
break;
case 'i': food = "Orange Juice";
price= 2.50;
break;
default: cout<<"Invalid item!" << endl;
}
const double tax = 0.0925;
double grat;
int quan;
cout << "Enter the quantity: ";
cin >> quan;
cout << "\n";
cout << setprecision(2) << fixed;
cout << "The item price for (" << quan << " x " << food << " is: $" << (quan*price) << ")" << endl;
cout << "The sales tax is: $" << tax*(quan*price) << "\n";
cout << "Enter the gratuity amount: $";
cin >> grat;
cout << "Your total price is $" << (tax*(quan*price))+(quan*price)+(grat) << "\n" << endl;
cout << "Thank you for your order!" << endl;
return 0;
}
|