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
|
#include "stdafx.h"
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
struct menuItemType
{string menuItem;
double menuPrice;
};
//function prototype declaration
void getdata( menuItemType[],menuItemType[],int&);
void showMenu( menuItemType[],int);
void printCheck(menuItemType[],int );
int main()
{
int items=0; //write down all menu items and their respective prices
menuItemType menuList[]={"plain egg",1.45,
"bacon and egg",2.45,
"muffin",0.99,
"french toast",1.99,
"fruit basket",2.49,
"cereal",0.69,
"coffee",0.50,
"tea",0.75
};
menuItemType order[10]; //write a welcome message
cout<<"Welcome to Hasib's Restaurant\n\n Please choose from the menu below\n\n Item\t price\n\n";
showMenu(menuList,8); //show menu from the data listed above
getdata(menuList,order,items);
printCheck(order,items);
system("pause");
return 0;
}
void printCheck(menuItemType order[],int items)
{int i;
double total=0,tax;
cout<<"Your Ordered Items are:\n Item\t price\n"; //confirm the items ordered on a single check
showMenu(order,items);
for(i=0;i<items;i++)
total+=order[i].menuPrice;
cout<<"\nItem total \t"<<"$"<<setprecision(2)<<fixed<<total<<endl;
tax=total*.05; //add a 5% tax to the subtotal before prinitng receipt
cout<<"Tax\t\t"<<"$"<<setprecision(2)<<fixed<<tax<<endl; //show the amount of tax
cout<<"Amount Due \t"<<"$"<<setprecision(2)<<fixed<<total+tax<<endl; //print the total amount after tax is added to the subtotal(for all the items on single order)
}
void getdata(menuItemType menu[],menuItemType order[],int& items)
{char yesno='Y';
int n;
while(toupper(yesno)=='Y')
{cout<<"Please enter your order item number below:\n "; //ask customer for order number and enter them below
cin>>n;
while(n<1||n>8)
{cout<<"invalid item number\n\n"; //if item number is not on the menu, show an error message and ask for another input
cout<<"Please choose any number between 1 and 8 only:\n "; //ask again for numbers given on the menu only
cin>>n;
}
order[items].menuItem=menu[n-1].menuItem;
order[items].menuPrice=menu[n-1].menuPrice;
items++;
cout<<"Would you like to add another item? \t (y/n)?\n "; //ask if customer wants to add more, if yes add to the order and recalculate the price at the end, if no calulate the appropriate amount
cin>>yesno;
}
}
void showMenu(menuItemType a[],int n)
{int i;
for(i=0;i<n;i++)
cout<<i+1<<". "<<setw(16)<<left<<a[i].menuItem<<"$"<<setprecision(2)<<fixed<<a[i].menuPrice<<endl;
}
|