Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to solve this problem that has been answered. I followed the instruc

ID: 3907512 • Letter: I

Question

I am trying to solve this problem that has been answered. I followed the instructions and I am unable to compile. My code:

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;   

struct menuItemType;

{

double menuitem[10];

double menuprice[10];

}

void getData(menuItemType &m,int &c);

void showMenu();

void printcheck (menuItemType &m, int c);

void main()

{

menuItemType menulist;

int c;

showMenu();

getData(menulist,c);

printcheck(menulist,c);

system("pause");

}

void showMenu()

{

cout<<"Welcome to Johnny's Restaurant"<<endl;

cout<<"1.Plain Egg"<<" "<<"$1.45"<<endl;

cout<<"2.Bacon & Egg"<<" "<<"$2.45"<<endl;

cout<<"3.Muffin"<<" "<<"$0.99"<<endl;

cout<<"4.French Toast"<<" "<<"$1.99"<<endl;

cout<<"5.Fruit Basket"<<" "<<"$2.49"<<endl;

cout<<"6.Cereal"<<" "<<"$0.69"<<endl;

cout<<"7.Coffee"<<" "<<"$0.50"<<endl;

cout<<"8.Tea"<<" "<<"$0.75"<<endl;

}

void getData(menuItemType &m,int &c)

{

int k;

int choice;

cout<<"Enter total # of items customer needs"<<endl;

cin>>c;

cout<<"Enter item numbers"<<endl;

for (k=0;k<c;k++)

{

cin>>choice;

switch(choice)

{

case 1:m.menuitem[k]="Plain Egg";

m.menuprice[k]= 1.45;

break;

case 2:m.menuitem[k]="Bacon & Egg";

m.menuprice[k]= 2.45;

break;

case 3:m.menuitem[k]="Muffin";

m.menuprice[k]= 0.99;

break;

case 4:m.menuitem[k]="French Toast";

m.menuprice[k]= 1.99;

break;

case 5:m.menuitem[k]="Fruit Basket";

m.menuprice[k]= 2.49;

break;

case 6:m.menuitem[k]="Cereal";

m.menuprice[k]= 0.69;

break;

case 7:m.menuitem[k]="Coffee";

m.menuprice[k]= 0.50;

break;

case 8:m.menuitem[k]="Tea";

m.menuprice[k]= 0.75;

break;

}

}

}

void printcheck(menuItemType &m,int c);

{

int j;

float price=0.0, tax=0.0,total;

cout<<"Johnny's"<<endl;

for(j=0;j<c;j++)

{

cout<<m.menuitem[j]<<" "<<m.menuprice[j]<<endl;

price=price+m.menuprice[j];

}

tax=0.05*price;

total=tax+price;

std::cout<<std::fixed;

std::cout<<std::setprecision(2);

cout<<"Tax="<<" "<<tax<<endl;

cout<<"Amount due="<<" "<<total<<endl;

}

Please provide a working code as well as explanation as to the errors.

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 and print the bill. Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item) Plain Egg Bacon and Egg Muffin French Toast Fruit Basket Cereal Coffee Tea $1.45 $2.45 $0.99 $1.99 $2.49 $0.69 $0.50 $0.75 Use an array, menuList, of the struct menuItemType, as defined i Programming Exercise 3. Your program must contain at least th following functions: Function getData: This function loads the data into the array menuList Function showMenu: This function shows the different item offered by the restaurant and tells the user how to select the items, Function printCheck: This function calculates and prints the check (Note that the billing amount should include a 5% tax.) A sample output is: ielcome to Johnny's Restaurant Bacon and Egg $2.45 Muffin Coffee Tax Amount Due $0.99 $0.50 $0.20 $4.14 Format your output with two decimal places. The name of each item in the output must be left justified. You may assume that the user selects only one item of a particular type.

Explanation / Answer

There were few errors in the code it has been corrected and two version of coding has been done

Version 1 is using string array in the menulist struct. and version 2 uses double and alternatively conditional code written to print output as string "Plain Egg" etc.,

Version 1 has completed code

Version 2 has the comments, which shows were you made some minor mistakes in earlier code.

Comments has been written where ever mistakes found. in version 2 for your reference.

///////////////

Version 1

//////////////////////////////

#include <iostream>
#include <string.h>
#include <iomanip>


using namespace std;

struct menuItemType{
//double menuitem[10];

char menuitem[10][100];

double menuprice[10];

};

void getData(menuItemType &m, int &c);

void showMenu();

void printcheck (menuItemType &m, int c);

int main()

{

menuItemType menulist;

int c;

showMenu();

getData(menulist,c);

printcheck(menulist,c);

return 0;

}

void showMenu()

{

cout<<"Welcome to Johnny's Restaurant"<<endl;
cout<<"1.Plain Egg"<<" "<<"$1.45"<<endl;
cout<<"2.Bacon & Egg"<<" "<<"$2.45"<<endl;
cout<<"3.Muffin"<<" "<<"$0.99"<<endl;
cout<<"4.French Toast"<<" "<<"$1.99"<<endl;
cout<<"5.Fruit Basket"<<" "<<"$2.49"<<endl;
cout<<"6.Cereal"<<" "<<"$0.69"<<endl;
cout<<"7.Coffee"<<" "<<"$0.50"<<endl;
cout<<"8.Tea "<<" "<<"$0.75"<<endl;

}

void getData(menuItemType &m,int &c)
{

int k;
int choice;
cout<<"Enter total # of items customer needs"<<endl;
cin>>c;
cout<<"Enter item numbers"<<endl;
for (k=0;k<c;k++)
{
cin>>choice;
switch(choice)
{

case 1: strcpy(m.menuitem[k],"Plain Egg ");
m.menuprice[k]= 1.45;
break;
case 2:strcpy(m.menuitem[k],"Beacon & Egg");
m.menuprice[k]= 2.45;
break;
case 3:strcpy(m.menuitem[k],"Muffin ");

m.menuprice[k]= 0.99;

break;

case 4:strcpy(m.menuitem[k],"French Toast");

m.menuprice[k]= 1.99;

break;

case 5:strcpy(m.menuitem[k],"Fruit Basket");

m.menuprice[k]= 2.49;

break;

case 6:strcpy(m.menuitem[k],"Cereal ");

m.menuprice[k]= 0.69;

break;

case 7:strcpy(m.menuitem[k],"Coffee ");

m.menuprice[k]= 0.50;

break;

case 8:strcpy(m.menuitem[k],"Tea ");

m.menuprice[k]= 0.75;

break;

}

}

}

void printcheck(menuItemType &m,int c)

{

int j;

float price=0.0, tax=0.0,total;

cout<<"Welcome to Johnny's Restaurant"<<endl;


for(j=0;j<c;j++)
{

cout<<m.menuitem[j]<<" "<<m.menuprice[j]<<endl;


price=price+m.menuprice[j];
}

tax=0.05*price;

total=tax+price;

std::cout<<std::fixed;

std::cout<<std::setprecision(2);

cout<<"Tax="<<" "<<tax<<endl;

cout<<"Amount due="<<" "<<total<<endl;

}

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////Version 2

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

// ERROR here is semicolon ;
struct menuItemType
{

double menuitem[10];

double menuprice[10];

};

void getData(menuItemType &m,int &c);

void showMenu();

void printcheck (menuItemType &m, int c);

//main menu has to return int datatype and there should be return 0 in the main function
int main()

{

menuItemType menulist;

int c;

showMenu();

getData(menulist,c);

printcheck(menulist,c);

//ERROR on system pause there is no such command to pause
//system function is used to call operation system commands
// getch() or getche() can be used with #include <conio.h>
//system("pause");
return 0;
}

void showMenu()

{

cout<<"Welcome to Johnny's Restaurant"<<endl;

cout<<"1.Plain Egg"<<" "<<"$1.45"<<endl;

cout<<"2.Bacon & Egg"<<" "<<"$2.45"<<endl;

cout<<"3.Muffin"<<" "<<"$0.99"<<endl;

cout<<"4.French Toast"<<" "<<"$1.99"<<endl;

cout<<"5.Fruit Basket"<<" "<<"$2.49"<<endl;

cout<<"6.Cereal"<<" "<<"$0.69"<<endl;

cout<<"7.Coffee"<<" "<<"$0.50"<<endl;

cout<<"8.Tea"<<" "<<"$0.75"<<endl;

}

void getData(menuItemType &m,int &c)

{

int k;

int choice;

cout<<"Enter total # of items customer needs"<<endl;

cin>>c;

cout<<"Enter item numbers"<<endl;

for (k=0;k<c;k++)

{

cin>>choice;

switch(choice)

{
// It is not possible to use String value "Plain Egg" to an double character array type
//either value to be in numbers ore data type has to be changed to character array[][]
case 1:m.menuitem[k]=1;

m.menuprice[k]= 1.45;

break;

case 2:m.menuitem[k]=2;

m.menuprice[k]= 2.45;

break;

case 3:m.menuitem[k]=3;

m.menuprice[k]= 0.99;

break;

case 4:m.menuitem[k]=4;

m.menuprice[k]= 1.99;

break;

case 5:m.menuitem[k]=5;

m.menuprice[k]= 2.49;

break;

case 6:m.menuitem[k]=6;

m.menuprice[k]= 0.69;

break;

case 7:m.menuitem[k]=7;

m.menuprice[k]= 0.50;

break;

case 8:m.menuitem[k]=8;

m.menuprice[k]= 0.75;

break;

}

}

}
// Semicolon used before function definition not allowed
void printcheck(menuItemType &m,int c)

{

int j;

float price=0.0, tax=0.0,total;

cout<<"Johnny's"<<endl;

double item=0;
for(j=0;j<c;j++)

{

item = m.menuitem[j];
if(item == 1)
{
cout<<"Plain Egg"<<" "<<m.menuprice[j]<<endl;
}else if(item == 2){
cout<<"Beacon and Egg"<<" "<<m.menuprice[j]<<endl;
}else if(item == 3){
cout<<"Muffin"<<" "<<m.menuprice[j]<<endl;
}else if(item == 4){
cout<<"French Toast"<<" "<<m.menuprice[j]<<endl;
}else if(item == 5){
cout<<"Fruit Basket"<<" "<<m.menuprice[j]<<endl;
}else if(item == 6){
cout<<"Cereal"<<" "<<m.menuprice[j]<<endl;
}else if(item == 7){
cout<<"Coffee"<<" "<<m.menuprice[j]<<endl;
}else if(item == 8){
cout<<"Tea"<<" "<<m.menuprice[j]<<endl;
}
//cout<<m.menuitem[j]<<" "<<m.menuprice[j]<<endl;

price=price+m.menuprice[j];

}

tax=0.05*price;

total=tax+price;

std::cout<<std::fixed;

std::cout<<std::setprecision(2);

cout<<"Tax="<<" "<<tax<<endl;

cout<<"Amount due="<<" "<<total<<endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote