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

my output is not right please help i use visual studios for my class #include<io

ID: 664262 • Letter: M

Question

my output is not right please help i use visual studios for my class

#include<iostream>

#include<string>

#include<iomanip>

#include<fstream>

using namespace std;

struct menuItemType

{

string menuItem;

double menuPrice;

};

int getdata(menuItemType[], menuItemType[], int);

void showMenu(menuItemType[], int);

void printCheck(menuItemType[], int);

int main()

{

int items = 0;

string line = "";

menuItemType menuList[25], order[25];

fstream myfile;

myfile.open("menu.txt");

if (myfile.is_open())

{

myfile >> menuList[items].menuItem >> menuList[items].menuPrice;

while (!myfile.eof())

{

items++;

myfile >> menuList[items].menuItem >> menuList[items].menuPrice;

}

myfile.close();

}

else cout << "Unable to open file";

cout << "Welcome to Johnny's Restaurant menu Item price ";

showMenu(menuList, items);

int i = getdata(menuList, order, items);

printCheck(order, i);

//Pause the system for a while

//system("pause");*/

return 0;

}

void printCheck(menuItemType order[], int items)

{

int i;

double total = 0, tax;

cout << "Your Check Ordered Items Item price ";

showMenu(order, items);

for (i = 0; i<items; i++)

total += order[i].menuPrice;

cout << " Items cost total " << "$" << setprecision(2) << fixed << total << endl;

tax = total*.05;

cout << "Tax " << "$" << setprecision(2) << fixed << tax << endl;

cout << "Amount Due " << "$" << setprecision(2) << fixed << total + tax << endl;

}

int getdata(menuItemType menu[], menuItemType order[], int items)

{

char yesno = 'Y';

int n;

int i = 0;

while (toupper(yesno) == 'Y')

{

while (true)

{

cout << "Enter your order item number(1 to 25) : ";

cin >> n;

if (n >= 1 && n <= items)

break;

cout << " Invalid menu choice?";

}

order[i].menuItem = menu[n - 1].menuItem;

order[i].menuPrice = menu[n - 1].menuPrice;

i++;

cout << "Would you like continue?(y/n)? ";

cin >> yesno;

}

return i;

}

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;

}

Explanation / Answer

#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>

using namespace std;

struct menuItemType

{

string menuItem;

double menuPrice;

};

int getdata(menuItemType[], menuItemType[], int);

void showMenu(menuItemType[], int);

void printCheck(menuItemType[], int);

int main()

{

int items = 0;

string line = "";

menuItemType menuList[25], order[25];

fstream myfile;

myfile.open("menu.txt");

if (myfile.is_open())

{

myfile >> menuList[items].menuItem >> menuList[items].menuPrice;

while (!myfile.eof())

{

items++;

myfile >> menuList[items].menuItem >> menuList[items].menuPrice;

}

myfile.close();

}

else cout << "Unable to open file";

cout << "Welcome to Johnny's Restaurant menu Item price ";

showMenu(menuList, items);

int i = getdata(menuList, order, items);

printCheck(order, i);

//Pause the system for a while

//system("pause");*/

return 0;

}

void printCheck(menuItemType order[], int items)

{

int i;

double total = 0, tax;

cout << "Your Check Ordered Items Item price ";

showMenu(order, items);

for (i = 0; i<items; i++)

total += order[i].menuPrice;

cout << " Items cost total " << "$" << setprecision(2) << fixed << total << endl;

tax = total*.05;

cout << "Tax " << "$" << setprecision(2) << fixed << tax << endl;

cout << "Amount Due " << "$" << setprecision(2) << fixed << total + tax << endl;

}

int getdata(menuItemType menu[], menuItemType order[], int items)

{

char yesno = 'Y';

int n;

int i = 0;

while (toupper(yesno) == 'Y')

{

while (true)

{

cout << "Enter your order item number(1 to 25) : ";

cin >> n;

if (n >= 1 && n <= items)

break;

cout << " Invalid menu choice?";

}

order[i].menuItem = menu[n - 1].menuItem;

order[i].menuPrice = menu[n - 1].menuPrice;

i++;

cout << "Would you like continue?(y/n)? ";

cin >> yesno;

}

return i;

}

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;

}