| | |
Menu Flaw - Query.
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Basically this Menu works however, when I enter in a string the default does catch it but then the Menu repeats the error so in essence isnt full proof. Would the way around this be to check the 1st entry by the user to see if its an integer, if so progress to the do while if not give an initial error message till they enter an integer? Or is there a wiser way around this annoying flaw? Thanks.
C++ Syntax (Toggle Plain Text)
do { // Do While Loop that incorporates Menu and List Functions system("cls"); //clears previous entries & redisplays the Menu per selection // Displays Menu Screen for user interaction of List cout << "**********Menu*************"<< endl; cout << "* 1. Populate List *"<< endl; cout << "* 2. Sort list *"<< endl; cout << "* 3. Search List *"<< endl; cout << "* 4. Display List *"<< endl; cout << "* 0. Exit *"<< endl; cout << "***************************"<< endl; cout << " "<< endl; cout << "Please select your option "<< endl; cin >> n; cout << " "<< endl; switch (n) { case 1 : disp.populate(); cout << "List populated."<< endl; system("Pause"); break; case 2 : disp.sort(); system("Pause"); break; case 3 : cout << "Please enter the value you wish to search from the List"<< endl; cin >> p; system("Pause"); break; case 4 : disp.toString(); system("Pause"); break; default: if (n !=0) { cout << "Enter a number relating to the Options shown!!!" << endl; system("Pause"); } break; } } while (n != 0); // Exit Condition system("Pause");
.........scaricamento.........
Your loop encompasses both the menu and the selector, as:
So if the option is bad, the menu gets displayed again anyway.
What you'd probably like instead is something that catches itself. You can do it several ways, but another loop will probably do just fine.
Hope this helps.
C++ Syntax (Toggle Plain Text)
do { display_menu(); select_option(); while (!done);
What you'd probably like instead is something that catches itself. You can do it several ways, but another loop will probably do just fine.
C++ Syntax (Toggle Plain Text)
do { display_menu(); do { select_option(); while (invalid_option); while (!done)
Hope this helps.
Hey Just use the return Statement to Exit.
and in the switch statments Add the following. So the program returns a value and ends.
and in the switch statments Add the following. So the program returns a value and ends.
C++ Syntax (Toggle Plain Text)
case 0: return 0; break;
![]() |
Other Threads in the C++ Forum
- Previous Thread: Help with program...can't get array to accept a struct
- Next Thread: Image. How to get an array that works properly?
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






