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
|
#include <iostream>
#include <iomanip>
using namespace std;
void showMenu ();
void showBill (float, float, float, float);
void changeDue (float, float);
int main()
{
float taxCalc, tipCalc, amountDue, tendered;
int choice;
float sum = 0;
enum CHOICE {CHOICE_HAMBURGER = 0, CHOICE_HOTDOG=1, CHOICE_PEANUTS=2, CHOICE_POPCORN=3, CHOICE_SODA=4, CHOICE_CHIPS=5, CHOICE_WATER=6, CHOICE_QUIT=7};
const float HAMBURGER=6.00, HOTDOG=4.50, PEANUTS=3.75, POPCORN=5.50, SODA=2.80, CHIPS=1.00, WATER=2.00;
const float price[] = {HAMBURGER, HOTDOG, PEANUTS, POPCORN, SODA, CHIPS, WATER};
do
{
showMenu();
while (choice != CHOICE_QUIT)
{
cout << "Enter menu item: ";
cin >> choice;
if (choice < CHOICE_HAMBURGER || choice > CHOICE_QUIT)
{
cout << "Please enter a valid menu choice: ";
cin >> choice;
}
sum = sum + price[choice];
cout<<setprecision(2)<<fixed;
taxCalc = .065 * sum;
tipCalc = .20 * sum;
amountDue = taxCalc + tipCalc + sum;
}
showBill(sum, amountDue, taxCalc, tipCalc);
cout<<"Enter amount tendered: ";
cin>>tendered;
changeDue(amountDue, tendered);
} while (choice != CHOICE_QUIT);
return 0;
}
//DISPLAY THE MENU FUNCTION--------------------------------------
void showMenu ()
{
cout << "\n\t\tBaseball Game Snacks\n\n"
<< "0. Hamburger $6.00\n"
<< "1. Hotdog $4.50\n"
<< "2. Peanuts $3.75\n"
<< "3. Popcorn $5.50\n"
<< "4. Soda $2.80\n"
<< "5. Chips $1.00\n"
<< "6. Water $2.00\n"
<< "7. End Order\n\n";
}
//DISPLAY THE BILL FUNCTION--------------------------------------
void showBill (float bill, float totBill, float tax, float tip)
{
cout<<"\nBill = $"<<bill<<endl;
cout<<"Tax = $"<<tax<<endl;
cout<<"Tip = $"<<tip<<endl;
cout<<"Total amount due = $"<<totBill<<endl;
}
//DISPLAY THE CHANGE DUE FUNCTION--------------------------------
void changeDue (float totBill, float amtTendered)
{
float change = amtTendered - totBill;
cout<<"Change due = $"<<change;
}
|