Advertisement
Old_But_Gold

CPP_input_check

Sep 3rd, 2024 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     const int MIN = 0;
  8.     const int MAX = 100;
  9.     int num;
  10.     bool IsIncorrect;
  11.     do {
  12.         IsIncorrect = false;
  13.         cin >> num;
  14.         if (cin.fail())
  15.         {
  16.             IsIncorrect = true;
  17.             cout << "TYPR ERR" << endl;
  18.             cin.clear();
  19.             while (cin.get() != '\n');
  20.         }
  21.         if (!IsIncorrect && (num < MIN || num > MAX))
  22.         {
  23.             IsIncorrect = true;
  24.             cout << "RANGE ERR" << endl;
  25.         }
  26.         if (cin.get() != '\n')
  27.         {
  28.             cout << "Err";
  29.             IsIncorrect = true;
  30.             cin.clear();
  31.             while (cin.get() != '\n');
  32.             cout << endl;
  33.         }
  34.     } while (IsIncorrect);
  35.     cout << num;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement