We have this project, it's about a program called like a cashier. What we need to do is, have an output where clients or users can select dishes from different categories. My question is, is it possible that a user can input his/her order by not overwriting the previous ones? Isn't it that data types are made to hold values? Another problem is that, when i try to go back to the categories, the previous inputted data is triggered which makes the program loop and loop and loop all over again. please help me, I'm a newbie and a student only. thank you.:disappoin This one is not yet done.so some parts are left blank. The colored code is where the infinite loop begins. Code: Here's the codes: [LEFT]#include <iostream> [/LEFT] #include <stdlib.h> #include <string> #include <Windows.h> /*This is a header to use, where all application programming interface in the microsoft windows operating system*/ #include <WinCon.h> #include <conio.h> using namespace std; string dish; string username; int main() { #define BLACK 0 //#define gives a meaningful name to a constant in your program #define BLUE 1 #define GREEN 2 #define CYAN 3 #define RED 4 #define MAGENTA 5 #define BROWN 6 #define LIGHTGREY 7 #define DARKGREY 8 #define LIGHTBLUE 9 #define LIGHTGREEN 10 #define LIGHTCYAN 11 #define LIGHTRED 12 #define LIGHTMAGENTA 13 #define YELLOW 14 #define WHITE 15 #define BLINK 128 //This is the start where you enter your username and password username = "cafe"; HANDLE outputhandle = GetStdHandle(STD_OUTPUT_HANDLE); //This sets a handle for standard input,output,error device. start: system("cls"); SetConsoleTextAttribute(outputhandle, 4+9); /*This sets the attributes of the characters written to the console screen buffer, where we have set a handle(HANDLE outputhandle); meaning we set a handle for our output device which is the MONITOR!*/ {cout << "Enter username: "; SetConsoleTextAttribute(outputhandle, 1+4); cin>>username; cout<<"\n"; string pass =""; char pas; SetConsoleTextAttribute(outputhandle, 4+9); cout << "Enter password: "; SetConsoleTextAttribute(outputhandle, 1+4); pas = getch(); //getch() allows the user to store the input from the keyboardsrokes while(pas != 13) //character 13 is enter { pass.push_back(pas); cout << '*'; pas = getch();} cout <<"\n"; if (pass == "2010" && username == "cafe" ) goto program2; else goto again; again: system("cls"); SetConsoleTextAttribute(outputhandle, 4+9); cout<<"Try Again?(Y/N): "; char response; SetConsoleTextAttribute(outputhandle, 1+4); cin>>response; switch (response) {case 'y': goto start; break; case 'Y': goto start; break; case 'n': goto exit; break; case 'N': goto exit; break; default : goto again; } } system("pause"); /*This is the start of program 2*/ //-------------------------------------------------------------------------------------------------------------------------------------------------// program2: system("cls"); // print, clear, then print again 5 times for (int i = 0; i < 3; i++) { system("cls"); SetConsoleTextAttribute(outputhandle, 1+4); cout<<" * ** * ******** ** ******** ******* *** *** ********"<<endl; cout<<" * * * * ** ** *** ** ** * ** ** * **"<<endl; cout<<" * * * * ******** ** ** ** ** * ** ** * ********"<<endl; cout<<" ** ** ** ** *** ** ** * **** * **"<<endl; cout<<" ** ** ******** ******* ******** ******* * ** * ********"<<endl; Sleep(300); //a function where delays the execution for an interval of time(milliseconds) system("cls"); SetConsoleTextAttribute(outputhandle, 4+9); cout<<" * ** * ******** ** ******** ******* *** *** ********"<<endl; cout<<" * * * * ** ** *** ** ** * ** ** * **"<<endl; cout<<" * * * * ******** ** ** ** ** * ** ** * ********"<<endl; cout<<" ** ** ** ** *** ** ** * **** * **"<<endl; cout<<" ** ** ******** ******* ******** ******* * ** * ********"<<endl; system("cls"); } goto program3; //-------------------------------------------------------------------------------------------------------------------------------------------------// [COLOR=Magenta]program3: system("cls"); //Start of program 3 [/COLOR] [COLOR=Magenta] cout<<""<<endl; cout<<""<<endl; cout<<""<<endl; cout<<""<<endl; cout<<""<<endl; [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); {cout<<"\t\t\t*CHOOSE FROM THE FOLLOWING CHOICES*"<<endl; cout<<""<<endl;} SetConsoleTextAttribute(outputhandle, 4+9); {cout<<"\t\t\tA).Pasta Dishes\n"; cout<<""<<endl;} SetConsoleTextAttribute(outputhandle, 1+4); {cout<<"\t\t\tB).Chicken\n"; cout<<""<<endl;} SetConsoleTextAttribute(outputhandle, 4+9); {cout<<"\t\t\tC).Veal\n"; cout<<""<<endl;} SetConsoleTextAttribute(outputhandle, 1+4); {cout<<"\t\t\tD).Seafood\n"; cout<<""<<endl;} SetConsoleTextAttribute(outputhandle, 4+9); {cout<<"\t\t\tE).Receipt\n"; cout<<""<<endl;} [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); char choice; [/COLOR] [COLOR=Magenta] cout<<"\t\t\tEnter the letter of your Choice: "; SetConsoleTextAttribute(outputhandle, 1+4); cin>>choice; [/COLOR] [COLOR=Magenta] { if (choice=='A'||choice=='a') goto pastamenu; else if (choice=='B'||choice=='b') goto chickenmenu; else if (choice=='C'||choice=='c') goto vealmenu; else if (choice=='D'||choice=='d') goto seafoodmenu; [/COLOR] [COLOR=Magenta] else if (choice=='E'||choice=='e') goto receipt; else goto program3; [/COLOR] [COLOR=Magenta] } [/COLOR] [COLOR=Magenta] system("pause"); //-------------------------------------------------------------------------------------------------------------------------------------------------//[/COLOR] [COLOR=Magenta] pastamenu: system("cls"); //Pasta Menu[/COLOR] [COLOR=Magenta] [/COLOR] [COLOR=Magenta] [/COLOR] [COLOR=Magenta] for (int b = 0; b<3 ; b++) {system("cls"); [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t PASTA DISHES "<<endl; [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; [/COLOR] [COLOR=Magenta] Sleep(500); system("cls"); [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; cout<<""<<endl; [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 4+9); cout<<"\t\t\t\t PASTA DISHES "<<endl; [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; } system("cls"); [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; cout<<""<<endl; [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 4+9); cout<<"\t\t\t\t PASTA DISHES "<<endl; [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; //-------------------------------------------------------------------------------------------------------------------------------------------------//[/COLOR] [COLOR=Magenta] [/COLOR] [COLOR=Magenta] cout<<""<<endl; cout<<""<<endl; [/COLOR] [COLOR=Magenta] cout<<"\t1. TOMATO SAUCE................................................. 9.50"<<endl; cout<<"\t2. BUTTER SAUCE................................................. 9.50"<<endl; cout<<"\t3. MARINARA..................................................... 9.95"<<endl; cout<<"\t4. OIL and GARLIC............................................... 9.95"<<endl; cout<<"\t5. RAVIOLI CHEESE or MEAT...................................... 10.25"<<endl; cout<<"\t6. CAVATELLI with TOMATO SAUCE................................. 10.25"<<endl; cout<<"\t7. ZITI with BROCCOLI.......................................... 10.50"<<endl; cout<<"\t8. MEATBALLS................................................... 10.95"<<endl; cout<<"\t9. SAUSAGE..................................................... 10.95"<<endl; cout<<"\t10. POTATO GNOCHI............................................... 10.95"<<endl; cout<<"\t11. PENNE VODKA SAUCE........................................... 11.25"<<endl; cout<<"\t12. SPINACH RAVIOLI............................................. 11.25"<<endl; cout<<"\t13. CAVATELLI WITH BROCCOLI..................................... 11.50"<<endl; cout<<"\t14. MEAT SAUCE.................................................. 11.50"<<endl; cout<<"\t15. MUSHROOM SAUCE.............................................. 11.50"<<endl; cout<<"\t16. TORTELLINI ALFREDO.......................................... 11.75"<<endl; cout<<"\t17. FETTUCCINI ALFREDO.......................................... 11.75"<<endl; cout<<"\t18. CLAM SAUCE,WHITE or RED..................................... 11.95"<<endl; cout<<"\t19. SAUSAGE and PEPPERS......................................... 12.25"<<endl; cout<<"\t20. LOBSTER RAVIOLLI............................................ 12.25"<<endl; cout<<""<<endl; [/COLOR] [COLOR=Magenta] cout<<"\t\t\tABOVE SERVED WITH SALAD & BREAD"<<endl; cout<<""<<endl; //-------------------------------------------------------------------------------------------------------------------------------------------------//[/COLOR] [COLOR=Magenta] [/COLOR] [COLOR=Magenta] //string dish; [/COLOR] [COLOR=Magenta] cout<<"\tWhat Dish Do You Prefer?: "; int item_to_order; SetConsoleTextAttribute(outputhandle, 4+9); cin>>item_to_order; [/COLOR] [COLOR=Magenta] switch (item_to_order) { case 1 : dish = "Tomato Sauce"; break; [/COLOR] [COLOR=Magenta] case 2 : dish = "Butter Sauce"; break; [/COLOR] [COLOR=Magenta] case 3 : dish = "Marinara"; break; [/COLOR] [COLOR=Magenta] case 4 : dish = "Oil and Garlic"; break; case 5 : dish = "Ravioli Cheese or Meat"; break; case 6 : dish = "Cavatelli with Tomato Sauce"; break; case 7 : dish = "Zitti with Broccoli"; break; case 8 : dish = "Meatballs"; break; case 9 : dish = "Sausage"; break; case 10 : dish = "Potato Gnochi"; break; case 11 : dish = "Penne Vodka Sauce"; break; case 12 : dish = "Spinach Ravioli"; break; case 13 : dish = "Cavatelli with Brocolli"; break; case 14 : dish = "Meat Sauce"; break; case 15 : dish = "Mushroom Sauce"; break; case 16 : dish = "Tortellini Al Fredo"; break; case 17 : dish = "Fettucini Al Fredo"; break; case 18 : dish = "Clam Sauce, White or Red"; break; case 19 : dish = "Sausage and Peppers"; break; case 20 : dish = "Lobster Ravioli"; break; [/COLOR] [COLOR=Magenta] } //-------------------------------------------------------------------------------------------------------------------------------------------------// [/COLOR] [COLOR=Magenta] cout<<""<<endl; [/COLOR] [COLOR=Magenta] [/COLOR] [COLOR=Magenta] cout<<"\tHow Many Orders?: "; [/COLOR] [COLOR=Magenta] int numberofitems; [/COLOR] [COLOR=Magenta] SetConsoleTextAttribute(outputhandle, 4+9); cin>>numberofitems; cout<<""<<endl; [/COLOR] [COLOR=Magenta] cout<<"\tTotal Of Your Orders"<<endl; [/COLOR] [COLOR=Magenta] cout<<""<<endl; cout<<"\tInitializing..."<<endl; [/COLOR] [COLOR=Magenta] cout<<"\tYour order(s) is/are "<< dish <<" with total number(s) of "<<numberofitems<<endl; //-------------------------------------------------------------------------------------------------------------------------------------------------//[/COLOR] [COLOR=Magenta] [/COLOR] [COLOR=Magenta] int resp; [/COLOR] [COLOR=Magenta] cout<<"\tIs There Anything You Want To Order?(Y/N): "; cin>>resp; [/COLOR] [COLOR=Magenta] { if (resp=='Y'||resp=='y') [/COLOR] [COLOR=Magenta] goto pastamenu; else cout<<"Proceeding To Choices"; [/COLOR] [COLOR=Magenta] Sleep(3000); [/COLOR] [COLOR=Magenta] goto program3; }[/COLOR] chickenmenu: system("cls"); system("pause"); vealmenu: system("cls"); system("pause"); seafoodmenu: system("cls"); system("pause"); receipt: system("cls"); system("pause"); exit: return 0; } Is it possible that I can total all of the orders on the last part of the program and all of it's cost?
your code is too messy stop using goto statements and use functions instead i fixed some things in your code see only tomato sauce from pasta dishes and do the same to other dishes Code: #include <iostream> #include <stdlib.h> #include <string> #include <Windows.h> /*This is a header to use, where all application programming interface in the microsoft windows operating system*/ #include <WinCon.h> #include <conio.h> using namespace std; #define BLACK 0 //#define gives a meaningful name to a constant in your program #define BLUE 1 #define GREEN 2 #define CYAN 3 #define RED 4 #define MAGENTA 5 #define BROWN 6 #define LIGHTGREY 7 #define DARKGREY 8 #define LIGHTBLUE 9 #define LIGHTGREEN 10 #define LIGHTCYAN 11 #define LIGHTRED 12 #define LIGHTMAGENTA 13 #define YELLOW 14 #define WHITE 15 #define BLINK 128 struct dish{ string name; int totalItems; double pricePerDish; }pastaDishes[21]; HANDLE outputhandle = GetStdHandle(STD_OUTPUT_HANDLE); //This sets a handle for standard input,output,error device. string dish; string username; void pastamenu(); int main(){ //This is the start where you enter your username and password username = ""; string pass =""; while (pass.compare("2010")!=0 || username.compare("cafe")!=0){ pass=""; system("cls"); SetConsoleTextAttribute(outputhandle, 4+9); /*This sets the attributes of the characters written to the console screen buffer, where we have set a handle(HANDLE outputhandle); meaning we set a handle for our output device which is the MONITOR!*/ cout << "Enter username: "; SetConsoleTextAttribute(outputhandle, 1+4); cin>>username; cout<<"\n"; char pas; SetConsoleTextAttribute(outputhandle, 4+9); cout << "Enter password: "; SetConsoleTextAttribute(outputhandle, 1+4); pas = getch(); //getch() allows the user to store the input from the keyboardsrokes while(pas != 13){ //character 13 is enter pass.push_back(pas); cout << '*'; pas = getch(); } cout <<"\n"; if(pass.compare("2010")!=0 || username.compare("cafe")!=0){ system("cls"); SetConsoleTextAttribute(outputhandle, 4+9); cout<<"Try Again?(Y/N): "; char response; SetConsoleTextAttribute(outputhandle, 1+4); cin>>response; if (response=='n' || response=='N'){ system("pause"); return 0; } } } //user logged successfully system("cls"); // print, clear, then print again 5 times for (int i = 0; i < 3; i++){ system("cls"); SetConsoleTextAttribute(outputhandle, 1+4); cout<<" * ** * ******** ** ******** ******* *** *** ********"<<endl; cout<<" * * * * ** ** *** ** ** * ** ** * ** "<<endl; cout<<" * * * * ******** ** ** ** ** * ** ** * ******** "<<endl; cout<<" ** ** ** ** *** ** ** * **** * ** "<<endl; cout<<" ** ** ******** ******* ******** ******* * ** * ******** "<<endl; Sleep(300); //a function where delays the execution for an interval of time(milliseconds) system("cls"); SetConsoleTextAttribute(outputhandle, 4+9); cout<<" * ** * ******** ** ******** ******* *** *** ********"<<endl; cout<<" * * * * ** ** *** ** ** * ** ** * ** "<<endl; cout<<" * * * * ******** ** ** ** ** * ** ** * ******** "<<endl; cout<<" ** ** ** ** *** ** ** * **** * ** "<<endl; cout<<" ** ** ******** ******* ******** ******* * ** * ******** "<<endl; system("cls"); } bool selected=false; while(!selected){ system("cls"); //Start of program 3 cout<<"\n\n\n\n\n"; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t*CHOOSE FROM THE FOLLOWING CHOICES*"<<endl; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 4+9); cout<<"\t\t\tA).Pasta Dishes\n"; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\tB).Chicken\n"; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 4+9); cout<<"\t\t\tC).Veal\n"; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\tD).Seafood\n"; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 4+9); cout<<"\t\t\tE).Receipt\n"; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 1+4); char choice; cout<<"\t\t\tEnter the letter of your Choice: "; SetConsoleTextAttribute(outputhandle, 1+4); cin>>choice; switch (choice){ case 'A': case 'a': pastamenu(); break; case 'B': case 'b': //chickenmenu(); break; case 'C': case 'c': //vealmenu(); break; case 'D': case 'd': //seafoodmenu(); break; case 'E': case 'e': selected=true; //receipt(); break; } } system("pause"); //-------------------------------------------------------------------------------------------------------------------------------------------------// return 0; } //functions void pastamenu(){ char resp='Y'; while (resp=='Y' || resp=='y'){ system("cls"); //Pasta Menu for (int b = 0; b<3 ; b++){ system("cls"); SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t PASTA DISHES "<<endl; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; Sleep(500); system("cls"); SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 4+9); cout<<"\t\t\t\t PASTA DISHES "<<endl; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; } system("cls"); SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; cout<<""<<endl; SetConsoleTextAttribute(outputhandle, 4+9); cout<<"\t\t\t\t PASTA DISHES "<<endl; SetConsoleTextAttribute(outputhandle, 1+4); cout<<"\t\t\t\t________________"<<endl; cout<<""<<endl; cout<<""<<endl; cout<<"\t1. TOMATO SAUCE................................................. 9.50"<<endl; cout<<"\t2. BUTTER SAUCE................................................. 9.50"<<endl; cout<<"\t3. MARINARA..................................................... 9.95"<<endl; cout<<"\t4. OIL and GARLIC............................................... 9.95"<<endl; cout<<"\t5. RAVIOLI CHEESE or MEAT...................................... 10.25"<<endl; cout<<"\t6. CAVATELLI with TOMATO SAUCE................................. 10.25"<<endl; cout<<"\t7. ZITI with BROCCOLI.......................................... 10.50"<<endl; cout<<"\t8. MEATBALLS................................................... 10.95"<<endl; cout<<"\t9. SAUSAGE..................................................... 10.95"<<endl; cout<<"\t10. POTATO GNOCHI............................................... 10.95"<<endl; cout<<"\t11. PENNE VODKA SAUCE........................................... 11.25"<<endl; cout<<"\t12. SPINACH RAVIOLI............................................. 11.25"<<endl; cout<<"\t13. CAVATELLI WITH BROCCOLI..................................... 11.50"<<endl; cout<<"\t14. MEAT SAUCE.................................................. 11.50"<<endl; cout<<"\t15. MUSHROOM SAUCE.............................................. 11.50"<<endl; cout<<"\t16. TORTELLINI ALFREDO.......................................... 11.75"<<endl; cout<<"\t17. FETTUCCINI ALFREDO.......................................... 11.75"<<endl; cout<<"\t18. CLAM SAUCE,WHITE or RED..................................... 11.95"<<endl; cout<<"\t19. SAUSAGE and PEPPERS......................................... 12.25"<<endl; cout<<"\t20. LOBSTER RAVIOLLI............................................ 12.25"<<endl; cout<<""<<endl; cout<<"\t\t\tABOVE SERVED WITH SALAD & BREAD"<<endl; cout<<""<<endl; cout<<"\tWhat Dish Do You Prefer?: "; int item_to_order; SetConsoleTextAttribute(outputhandle, 4+9); cin>>item_to_order; cout<<"\tHow Many Orders?: "; int numberofitems; SetConsoleTextAttribute(outputhandle, 4+9); cin>>numberofitems; cout<<""<<endl; switch (item_to_order){ case 1 : dish = "Tomato Sauce"; pastaDishes[1].name=dish; pastaDishes[1].totalItems+=numberofitems; pastaDishes[1].pricePerDish=9.50; break; case 2 : dish = "Butter Sauce"; break; case 3 : dish = "Marinara"; break; case 4 : dish = "Oil and Garlic"; break; case 5 : dish = "Ravioli Cheese or Meat"; break; case 6 : dish = "Cavatelli with Tomato Sauce"; break; case 7 : dish = "Zitti with Broccoli"; break; case 8 : dish = "Meatballs"; break; case 9 : dish = "Sausage"; break; case 10 : dish = "Potato Gnochi"; break; case 11 : dish = "Penne Vodka Sauce"; break; case 12 : dish = "Spinach Ravioli"; break; case 13 : dish = "Cavatelli with Brocolli"; break; case 14 : dish = "Meat Sauce"; break; case 15 : dish = "Mushroom Sauce"; break; case 16 : dish = "Tortellini Al Fredo"; break; case 17 : dish = "Fettucini Al Fredo"; break; case 18 : dish = "Clam Sauce, White or Red"; break; case 19 : dish = "Sausage and Peppers"; break; case 20 : dish = "Lobster Ravioli"; break; } //-------------------------------------------------------------------------------------------------------------------------------------------------// cout<<""<<endl; cout<<"\tTotal Of Your Orders"<<endl; cout<<""<<endl; cout<<"\tInitializing..."<<endl; cout<<"\tYour order(s) is/are "; for (int j=1;j<=20;j++) if (pastaDishes[j].totalItems>0) cout<< pastaDishes[j].name<<" with total number(s) of "<<pastaDishes[j].totalItems<<endl; cout<<"\tIs There Anything You Want To Order?(Y/N): "; cin>>resp; if (resp!='Y' && resp!='y'){ cout<<"Proceeding To Choices"; return; } } }