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 127 128 129 130 131 132 133 134
|
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
//structure with both the item's name, and price of said item;
struct menuItemType {
string item;
double price;
} ;
void displayMenu(); //displays menu along with item numbers
void getData(menuItemType& menuList, string item, double price); //loads data into the array menuList
void printCheck(menuItemType& menuList, int n); //calculates, and displays the check, formatted to 2 dec. places
void main()
{
const int breakfast = 7; //const int for the 8 breakfast items listed
menuItemType menuList[breakfast]; //array menuList includes item name with prices
int order;
double price;
string item;
int i=0; //counter for adding items to array
cout << "Welcome to Johnny's Restaurant! \n\n"
"Our menu options for today are:\n\n ";
displayMenu(); //displays the menu with item numbers included
cout << "Please select your choices by item number!\n"
"To order, please enter the item numbers you wish to order.\n"
"ex: to order coffee and an egg, the order would be: 7 1\n\n"
"To stop ordering, type s, then hit enter.\n\n"
"In consideration to others, we ask that you not order\n"
"more than one of each item please! \n\n";
//ordering loop below, by item number
while (cin >> order)
{
displayMenu();
switch (order)
{
case 1:
{
item = "Plain egg";
price = 1.45;
break;
}
case 2:
{
item = "Bacon with egg";
price = 2.45;
break;
}
case 3:
{
item = "Muffin";
price = 0.99;
break;
}
case 4:
{
item = "French Toast";
price = 1.99;
break;
}
case 5:
{
item = "Fruit Basket";
price = 2.49;
break;
}
case 6:
{
item = "Cereal";
price = 0.69;
break;
}
case 7:
{
item = "Coffee";
price = 0.50;
break;
}
case 8:
{
item = "Tea";
price = 0.75;
break;
}
default:
{
cout << "We do not carry that selection, sorry. \n"
"Please attempt your order again!\n";
continue;
}
}
getData(menuList[i], item, price);
++i; //increases counter by 1
if (i==8)
break;
}
printCheck(menuList[0], i);
}
void displayMenu()
{
cout <<
"\n "
"Item #--Item-------------------Price----\n"
" 1 Plain egg $1.45\n"
" 2 Bacon and egg $2.45\n"
" 3 Muffin $0.99\n"
" 4 French Toast $1.99\n"
" 5 Fruit Basket $2.49\n"
" 6 Cereal $0.69\n"
" 7 Coffee $0.50\n"
" 8 Tea $0.75\n"
"----------------------------------\n";
}
void getData(menuItemType& menuList, string item, double price)
{
menuList.item = item;
menuList.price = price;
}
void printCheck(menuItemType& menuList, int n)
{
for(int i=0; i < n ; ++i)
{
cout << menuList.item << " " << menuList.price << "\n";
}
}
|