Simple question about syntax error. I have this program that i'm trying to implement with classes but I get errors, its

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Simple question about syntax error. I have this program that i'm trying to implement with classes but I get errors, its

Post by answerhappygod »

Simple question about syntax error. I have this program that i'mtrying to implement with classes but I get errors, its notrecognizing the menuItemType struct "menuList" in the mainfunction. Please help me with the errors. #include #include#include #include using namespace std; const int menuItems = 8;menuItemType menuList[menuItems]; struct menuItemType { //VARIABLES string menuItem; double menuPrice; int count_1; //variable initializon menuItemType() { menuItem = ""; menuPrice =0.0; count_1 = 0; } }; //const int menuItems = 8; //menuItemTypemenuList[menuItems]; class menuClass { private: string itemName;double price; public: struct menuItemType { // VARIABLES stringmenuItem; double menuPrice; int count_1; // variable initializonmenuItemType() { menuItem = ""; menuPrice = 0.0; count_1 = 0; } };menuClass() { struct menuItemType { // VARIABLES string menuItem;double menuPrice; int count_1; // variable initializonmenuItemType() { menuItem = ""; menuPrice = 0.0; count_1 = 0; } };} menuClass(string Name, double Price) { itemName = Name; price =Price; } // getter for item name string getName() { returnitemName; } // getter for item price double getPrice() { returnprice; } void showMenu(menuItemType menuList[], int x) { //Function variables int count; cout << "Welcome to Johnny'sRestaurant! " << endl; cout << " ===== Menu List======" << endl; for (count = 0; count < x; count++) {cout << setw(1) << left << "[" << count + 1<< "]"; cout << setw(20) << left <<menuList[count].menuItem << '$' <<menuList[count].menuPrice << endl; } } //void data goes belowvoid getData(menuItemType menuList[]) { ifstream myFile; stringitem, s; double price; int i = 0; myFile.open("menu.txt"); while(getline(myFile, item, '$')) { myFile >> price;getline(myFile, s, '\n'); menuList.menuItem = item;menuList.menuPrice = price; i++; } myFile.close(); } voidprintCheck(menuItemType menuList[]) { double checkTotal = 0; doublecheckTax = 0; const double TAX = .05; cout << "\t===== ORDERSUMMARY =====" << endl; for (int i = 0; i < 8; i++) { if(menuList.count_1 != 0) { cout << setw(5) << left<< menuList.count_1 << setw(20) << left<< menuList.menuItem << '$' <<menuList.menuPrice * menuList.count_1 << endl;checkTotal += (menuList.menuPrice * menuList.count_1); } }checkTax = checkTotal * TAX; checkTotal += checkTax; cout <<setw(15) << left << " Tax" << setw(11) <<right << "$" << checkTax << endl; cout <<setw(14) << left << " Amount Due " << setw(12)<< right << "$" << checkTotal << endl;system("pause"); } }; const int menuItems = 8; menuItemTypemenuList[menuItems]; int main() { const int menuItems = 8;menuItemType menuList[menuItems]; // set precision to 2 for moneycout << setprecision(2) << std::fixed; // functions& variable int orderChoice = 0; bool ordering = true; int count= 0; // FUNCTION CALLING menuClass obj; obj.getData(menuList);obj.showMenu(menuList, menuItems); while (ordering) { cout <<"Select your desired item... \n"; cout << "Type 0 if you arefinish ordering." << endl; cin >> orderChoice; if((orderChoice > 0 && orderChoice <= menuItems)&& menuList[orderChoice - 1].count_1 > 0) {++menuList[orderChoice - 1].count_1; } else if (orderChoice > 0&& orderChoice <= menuItems) { ++menuList[orderChoice -1].count_1; } else { ordering = false; } }obj.printCheck(menuList); return 0; }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply