You are on page 1of 4

#include #include #include #include

<iostream> <cctype> <cstdlib> <iomanip>

using namespace std; int main() { char choice='Y'; int order = 1; int num1=0, num2=0, num3=0, num4=0, num5=0; int num_customers; int sentinel=0; const double UnitPrice1= 6.95, UnitPrice2= 5.75,UnitPrice3= 7.25, UnitPrice4= 8.95, UnitPrice5= 4.95; double AmountofSale1=0, AmountofSale2=0, AmountofSale3=0, AmountofSale4=0, AmountofSale5=0; cout<<"___________________Menu________________\n\n" <<"_____(1) Buffalo_Wings $6.95_____\n" <<"_____(2) Super_Burger $5.75_____\n" <<"_____(3) Italian_Sandwich $7.25_____\n" <<"_____(4) Shrimp_Nuggets $8.95_____\n" <<"_____(5) Veggie_Supreme $4.95_____\n";

while (order != sentinel) { cout<<"From the list of food, what would you like:\n"; cin>>order; switch(order) { case 0: break; case 1: cout<<"How many Buffalo Wings would you like to order:\n"; cin>>num1; AmountofSale1 = UnitPrice1 * num1; break;

case 2: cout<<"How many Super Burgers would you like to order:\n";

cin>>num2; AmountofSale2= UnitPrice2 * num2; break; case 3: cout<<"How many Italian Sandwiches would you like to order:\n"; cin>>num3; AmountofSale3= UnitPrice3 * num3; break;

case 4: cout<<"How many Shrimp Nuggets would you like to order:\n"; cin>>num4; AmountofSale4= UnitPrice4 * num4; break;

case 5: cout<<"How many would Veggie Supremes you like to order:\n"; cin>>num5; AmountofSale5= UnitPrice5 * num5; break; default: cout<<"Please choose a valid item from our list\n"; } { cout<<"You have ordered:\n\n"; cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n"; cout<<"Buffalo Wings"<<setw(6)<<left<< num1 <<setw(16)<<right<< UnitPrice1 <<setw(20) <<right<< AmountofSale1<<endl; cout<<"Super Burger:"<<setw(6)<<left<< num2 <<setw(16)<<right<< UnitPrice2 <<setw(20) <<right<< AmountofSale2<<endl<<endl; cout<<"Italian Sandwich:"<<setw(6)<<left<< num3 <<setw(16)<<right<< UnitPrice3 <<setw(20) <<right<< AmountofSale3<<endl<<endl; cout<<"Shrimp Nuggets:"<<setw(6)<<left<< num4 <<setw(16)<<right<< UnitPrice4 <<setw(20) <<right<< AmountofSale4<<endl<<endl; cout<<"Veggie Supreme:"<<setw(6)<<left<< num5 <<setw(16)<<right<< UnitPrice5 <<setw(20) <<right<< AmountofSale5<<endl<<endl;

} } system("PAUSE"); return 0; } __________________ struct menuItem{ //this constructor will allow us to easily add items to the vector //It's not 100% exception safe though menuItem(string a, double b): itemName(a), itemCost(b) {} string itemName; double itemCost; }; int main() {

int num1, order; vector<menuItem> myMenu; myMenu.push_back(menuItem("Buffalo Wings", 6.95)); //Add Buffalo Wings to myMenu.push_back(menuItem("Super Burger", 5.75)); //Add Super burger to myMenu.push_back(menuItem("Italian Sandwich", 7.25)); //etc for each Menu

the menu the menu Item

//Now to display the menu cout << " Menu" << endl; cout.setf(ios::left); //Make fields left justified for(unsigned int x = 0; x < myMenu.size(); x++) cout << x+1 << ". "<< setw(20) << myMenu[x].itemName << "$" << myMenu[x].itemCost << endl; cout << endl; //No need for a big switch statement anymore: //Once you've got your order number... order = 2; //**** //IMPORTANT NOTE //Vectors are 0 based. //Your Input is 1 based (0 to cancel out of Order code) //Make sure you keep that in mind when dealing with user input //In menu above, 1 is added to X for display //In the prompt below, 1 is subtracted from user input cout << "How many orders of " << myMenu[order-1] << " would you like?" << endl; //Rest of your code here: } ____________________struct singleOrder{ singleOrder(unsigned int io, unsigned int ni): itemOrdered(io), numItems(ni) {} unsigned int itemOrdered; unsigned int numItems;

}; //Create a vector to contain all the orders made vector<singleOrder> orderHistory; //Once you've prompted for the item Number and number of items, insert that order into your order history like this: //orderHistory.push_back(singleOrder(itemNum, numItems)); //Quick Sample of how to generate a report for(unsigned int x = 0; x < myMenu.size(); x++){ double totalSales = 0; unsigned int totalQuantity = 0; for(unsigned int y = 0; y < orderHistory.size(); y++) if(orderHistory[y].itemOrdered == x) totalQuantity += orderHistory[y].numItems; totalSales = totalQuantity * myMenu[x].itemCost; cout << setw(20) << myMenu[x].itemName << setw(5) << totalQuantity << "$" << totalSales << endl; } ______________ while ( order!=sentinel || order==sentinel )

You might also like