Fix this code please #include #include #include #include Using namespace std; //Structure to hold each menu item Struct Menultem. { String name; Double price; }; //Function that reads data from file Int getData(struct Menultem menuList[]) { //Opening file for reading Fstream fin("menu.txt", ios::in); Int i=0; Struct Menultem temp; //Loop till entire data is processed While(fin.good()) { //Getting name Getline(fin, temp.name); //Reading price Fin >> temp.price; Fin.ignore(); //Storing in array menuList[i] = temp; i++; } //Closing file Fin.close(); Return i; } //Function that displays menu Void showMenu(struct Menultem menuList[], int cnt) Int i; Cout<<"\n Welcome to the Programmers' Cafe \n\n-Today's Menu--------\n"; //Looping over menu and printing to user For(i=0; i> ch; //Loop till user wants to stop While(ch == 'y' || ch == 'Y') { //Reading item number Cout << "\n\n Enter item number: "; Cin >> temp; While(temp <1 || temp > cnt) { //Reading item number. Cout<<"\n\n Enter item number between 1 and " << cnt << ": "; Cin >> temp; } //Storing in array Item[i] = temp; //Reading item quantity Cout << "\n Enter item quantity: "; Cin >> temp; //Storing in array Quantity[i] temp; //Prompting user again Cout << "\n\n Select another item? (y/n): "; Cin >> ch; } Return i; } //Function that calculates the price Void priceCheck(struct Menultem menuList[], int item[], int quantity[], int items) { Int i=0; Double total = 0, tax; Cout << "\n\n Thank you for eating at The Programmers' Cafe\n\n"; Cout << " Cout << "\n" << left <
Fix this code please
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
Using namespace std;
//Structure to hold each menu item
Struct Menultem.
{
String name;
Double price;
};
//Function that reads data from file Int getData(struct Menultem menuList[]) {
//Opening file for reading
Fstream fin("menu.txt", ios::in);
Int i=0;
Struct Menultem temp;
//Loop till entire data is processed While(fin.good())
{
//Getting name
Getline(fin, temp.name);
//Reading price
Fin >> temp.price;
Fin.ignore();
//Storing in array
menuList[i] = temp;
i++;
}
//Closing file
Fin.close();
Return i;
}
//Function that displays menu
Void showMenu(struct Menultem menuList[], int cnt)
Int i;
Cout<<"\n Welcome to the Programmers' Cafe \n\n-Today's Menu--------\n";
//Looping over menu and printing to user
For(i=0; i<cnt; i++)
{
//Printing menu item
Cout << fixed << setprecision(2];
Cout << "\n" << right <<setw(3) << (i+1) << " " << left <<setw(25) << menuList[i].name << left << setw(2) << "$" << left <<setw(10) << menuList[i].price;
}
Cout << "\n \n";
}
//Function that reads user selection
Int makeSelection(int item[], int quantity[], int cnt)
Int i=0, temp;
Char ch;
//Prompting user
Cout << "\n\n Do you want place an order? (y/n): ";
Cin >> ch;
//Loop till user wants to stop
While(ch == 'y' || ch == 'Y')
{
//Reading item number
Cout << "\n\n Enter item number: ";
Cin >> temp;
While(temp <1 || temp > cnt)
{
//Reading item number.
Cout<<"\n\n Enter item number between 1 and " << cnt << ": ";
Cin >> temp;
}
//Storing in array
Item[i] = temp;
//Reading item quantity
Cout << "\n Enter item quantity: ";
Cin >> temp;
//Storing in array
Quantity[i] temp;
//Prompting user again
Cout << "\n\n Select another item? (y/n): ";
Cin >> ch;
}
Return i;
}
//Function that calculates the price
Void priceCheck(struct Menultem menuList[], int item[], int quantity[], int items)
{
Int i=0;
Double total = 0, tax;
Cout << "\n\n Thank you for eating at The Programmers' Cafe\n\n";
Cout << "
Cout << "\n" << left <<setw(20) << "Receipt" << left <<setw(5) << "Qty" << left <<setw(5) << "Amount
\n";
Cout<<
-\n";
Cout << fixed << setprecision(2);
//Printing menu selected
For(i=0; i<items; i++)
Cout << "\n" << left <<setw(20) << menuList[item[i] -1].name << left <<setw(5) << quantity[i] << left <<setw(2) << "$" << left <<setw(2) << (quantity[i]* (menuList[item[i] -1].price]);
Total += (quantity[i]* (menuList[item[i] - 1].price));
}
//Calculating tax
Tax (7/100.0) * total;
//Printing tax
Cout << "\n\n" << left <<setw(25) << "Tax " << left <<setw(2) << "$" << left <<setw(2) << tax;
//Printing total amount due
Cout << "\n\n" << left <<setw(25) << "Amount Due " << left <<setw(2) << "$" << left <<setw(2) << (total + tax) << "\n\n";
}
//Main function
Int main()
Struct Menultem menuList[10];
Int item[20], quantity[20];
Int totalltems, cnt;
//Reading data
Cnt= getData(menuList);
//Displaying menul
showMenu(menuList, cnt);
//Making user selection.
totalltems makeSelection(item, quantity, cnt);
//Checking price
priceCheck(menuList, item, quantity, totalltems);
cout << "\n\n";
return 0;
}
Step by step
Solved in 2 steps with 1 images