Menu Flaw - Query.

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2007
Posts: 57
Reputation: Run.[it] is an unknown quantity at this point 
Solved Threads: 1
Run.[it]'s Avatar
Run.[it] Run.[it] is offline Offline
Junior Poster in Training

Menu Flaw - Query.

 
0
  #1
May 28th, 2008
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.

  1. do { // Do While Loop that incorporates Menu and List Functions
  2. system("cls"); //clears previous entries & redisplays the Menu per selection
  3. // Displays Menu Screen for user interaction of List
  4. cout << "**********Menu*************"<< endl;
  5. cout << "* 1. Populate List *"<< endl;
  6. cout << "* 2. Sort list *"<< endl;
  7. cout << "* 3. Search List *"<< endl;
  8. cout << "* 4. Display List *"<< endl;
  9. cout << "* 0. Exit *"<< endl;
  10. cout << "***************************"<< endl;
  11. cout << " "<< endl;
  12. cout << "Please select your option "<< endl;
  13. cin >> n;
  14. cout << " "<< endl;
  15.  
  16. switch (n)
  17. {
  18. case 1 :
  19. disp.populate();
  20. cout << "List populated."<< endl;
  21. system("Pause");
  22. break;
  23. case 2 :
  24. disp.sort();
  25. system("Pause");
  26. break;
  27. case 3 :
  28. cout << "Please enter the value you wish to search from the List"<< endl;
  29. cin >> p;
  30. system("Pause");
  31. break;
  32. case 4 :
  33. disp.toString();
  34. system("Pause");
  35. break;
  36. default:
  37. if (n !=0)
  38. {
  39. cout << "Enter a number relating to the Options shown!!!" << endl;
  40. system("Pause");
  41. }
  42. break;
  43. }
  44. }
  45. while (n != 0); // Exit Condition
  46. system("Pause");
.........scaricamento.........
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Menu Flaw - Query.

 
1
  #2
May 28th, 2008
Your loop encompasses both the menu and the selector, as:
  1. do {
  2. display_menu();
  3. select_option();
  4. while (!done);
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.
  1. do {
  2. display_menu();
  3. do {
  4. select_option();
  5. while (invalid_option);
  6. while (!done)

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 678
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 101
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: Menu Flaw - Query.

 
1
  #3
May 29th, 2008
Hey Just use the return Statement to Exit.

and in the switch statments Add the following. So the program returns a value and ends.
  1. case 0:
  2.  
  3. return 0;
  4.  
  5. break;
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 57
Reputation: Run.[it] is an unknown quantity at this point 
Solved Threads: 1
Run.[it]'s Avatar
Run.[it] Run.[it] is offline Offline
Junior Poster in Training

Re: Menu Flaw - Query.

 
0
  #4
May 29th, 2008
Cheers guys - Duoas and Sky Diploma.

Ill attempt both suggestions!
.........scaricamento.........
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 472 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC