I have been working on a project for a programming class. The problem is as follows:
"Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:
a. Show the customer the different breakfast items offered by the restaurant
b. Allow the customer to select more than one item from the menu.
c. Calculate the bill
The problem provides a list of food items and prices.
Define a struct menuItemType with two components to hold the name and price of an item. Use an array, menuList, of the menuItemTypes. Your program must contain at least the following functions:
-Function GetData: This function loads data into the array
-Function ShowMenu: Displays items offered by restaurant and tells user how to select items.
-Function printCheck: calculates and prints check(Note that the billing amount should include a 5% tax"
I am mainly stuck on this issue: how do I transfer information on which items the user selected from showMenu() into printCheck() in order to list and add up just those item prices in the check? I think my getData and showMenu functions are written correctly, as well as the rest of the program, but I am not sure what to do about printCheck. If you could provide any helpful advice on what logic to follow or send some code for this, I would be deeply grateful. Does this require an extra function?
I also cannot make the getData function work yet, it only reads in the first item and price but not the rest.
Here is relevant code I've written so far:
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
|
void getData(menuType menuList[], int counter)
{
while (!inData.eof())
{
inData>>menuList[counter].name>>menuList[counter].itemPrice;
counter++; }
}
void showMenu(menuType menuList[], char selection, int counter)
{
cout<<"This menu includes the following: "<<endl;
cout<<fixed<<showpoint<<setprecision(2);
cout<<menuList[counter].name<<setw(2 <<menuList[counter].itemPrice<<endl;
do {
cout<<"Enter the capital first letter of the item you want."<<endl;
cout<<"Press 'N' for chicken kabob."<<endl;
cout<<"Lastly, press 'Z' when you are finished."<<endl;
cin>>selection;
switch(selection)
{
case 'F':
cout<<menuList[0].name<<" "<<menuList[0].itemPrice<<endl;
break;
case 'C':
cout<<menuList[1].name<<" "<<menuList[1].itemPrice<<endl;
break;
case 'R':
cout<<menuList[2].name<<" "<<menuList[2].itemPrice<<endl;
break;
case 'N':
cout<<menuList[3].name<<" "<<menuList[3].itemPrice<<endl;
break;
case 'B':
cout<<menuList[4].name<<" "<<menuList[4].itemPrice<<endl;
break;
case 'L':
cout<<menuList[5].name<<" "<<menuList[5].itemPrice<<endl;
break;
case 'G':
cout<<menuList[6].name<<" "<<menuList[6].itemPrice<<endl;
break;
case 'S':
cout<<menuList[7].name<<" "<<menuList[7].itemPrice<<endl;
break;
default:
cout<<"Invalid selection, try again please."<<endl;
} //end of switch-case
} while (selection != 'Z');
}
void printCheck(menuType menuList[], int counter)
{
}
|
I did not include the input file itself here. Thank you very much for any hints or help in advance!
Best,
Kei