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
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// struct definition and declaration
struct menuItemType
{
string menuItem;
double itemPrice;
} plainEgg, baconEgg, muffin, frenchToast, fruitBasket, cereal, coffee, tea;
// function prototype
void getData(menuItemType menuList[]);
void showMenu(menuItemType menuList[], int x);
void printCheck(menuItemType menuList[],int userOrder[], int x);
// constants
const int MENU_ITEMS = 8;
const double SALES_TAX = 0.05;
int main()
{
menuItemType menuList[MENU_ITEMS];
int userOrder[MENU_ITEMS] = {0};
int orderChoice = 0;
bool ordering = true;
int count = 0;
getData(menuList);
showMenu(menuList, MENU_ITEMS);
while (ordering)
{
cout << "Please enter the number of the item that corresponds to the item you would like to purchase. Enter 0 to finalize your order." << endl;
cin >> orderChoice;
if (orderChoice > 0 && orderChoice <= MENU_ITEMS)
{
userOrder[orderChoice - 1] += 1;
}
else
ordering = false;
}
printCheck(menuList, userOrder, MENU_ITEMS);
return 0;
}
void getData(menuItemType menuList[])
{
// initizlize menuItemType variables
plainEgg.menuItem = "Plain Egg";
plainEgg.itemPrice = 1.45;
baconEgg.menuItem = "Bacon and Egg";
baconEgg.itemPrice = 2.45;
muffin.menuItem = "Muffin";
muffin.itemPrice = 0.99;
frenchToast.menuItem = "French Toast";
frenchToast.itemPrice = 1.99;
fruitBasket.menuItem = "Fruit Basket";
fruitBasket.itemPrice = 2.49;
cereal.menuItem = "Cereal";
cereal.itemPrice = 0.69;
coffee.menuItem = "Coffee";
coffee.itemPrice = 0.50;
tea.menuItem = "Tea";
tea.itemPrice = 0.75;
menuList[0] = plainEgg;
menuList[1] = baconEgg;
menuList[2] = muffin;
menuList[3] = frenchToast;
menuList[4] = fruitBasket;
menuList[5] = cereal;
menuList[6] = coffee;
menuList[7] = tea;
}
void showMenu(menuItemType menuList[], int x)
{
int count;
cout << "----------Welcome to Gloria's Glorious Breakfast Nook----------" << endl;
for (count = 0; count < x; count++)
{
cout << fixed << setprecision(2) << "[" << count + 1 << "]" << menuList[count].menuItem << right << setw(20) << "$" << menuList[count].itemPrice << endl;
}
}
void printCheck(menuItemType menuList[], int userOrder[], int MENU_ITEMS)
{
double amountDue = 0;
double tax;
cout << "---------------Customer's Check:---------------" << endl;
for (int i = 0; i < MENU_ITEMS; i++)
{
if (userOrder[i] > 0)
{
cout << fixed << setprecision(2) << menuList[i].menuItem << right << setw(20) << "$" << (menuList[i].itemPrice * userOrder[i]) << endl;
amountDue += (menuList[i].itemPrice * userOrder[i]);
}
}
tax = amountDue * SALES_TAX;
cout << "Tax:" << right << setw(14) << "$" << tax << endl;
cout << "Amount Due:" << right << setw(14) << "$" << amountDue << endl;
}
|