Leeen

функция проверки вводимого числа

Apr 25th, 2020
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. int enter_n() {
  2.  int n;
  3.   while (true)
  4.     {
  5.         cout << "Enter a n value: ";
  6.         cin >> n;
  7.         if (cin.fail())
  8.         {
  9.             cin.clear();
  10.             cin.ignore(32767,'\n');
  11.             cout << "Oops, that input is invalid.  Please try again.\n";
  12.         }
  13.         else
  14.         {
  15.             cin.ignore(32767,'\n');
  16.  
  17.             return n;
  18.         }
  19.     }
  20. }
Add Comment
Please, Sign In to add comment