| | |
Menu Flaw - Query.
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
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?
Views: 472 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






