Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. int getValue(const string & prompt)
  2. {
  3.     int val;
  4.    
  5.     if (cout << prompt, !(cin >> val))
  6.     {
  7.         cin.clear();
  8.         dumpLine();
  9.         return -1;
  10.     }
  11.     return val;
  12. }
  13.  
  14.  
  15. int main(void)
  16. {
  17.     //whatever else menu code or w/e you have here
  18.     int userReply = 0;
  19.     do{
  20.         userReply = getValue("Choose something between 1 and 4: ");
  21.     }while(userReply <= 0 || userReply >= 5);
  22.  
  23.     // and once the user picks a good choice between 1 and 4, do other shit
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement