Advertisement
anticlown

Простая проверка для C++

Sep 16th, 2024
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 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.  
  12.     do {
  13.         IsIncorrect = false;
  14.         cin >> num;
  15.  
  16.         if (cin.fail())
  17.         {
  18.             IsIncorrect = true;
  19.             cout << "TYPR ERR" << endl;
  20.             cin.clear();
  21.             while (cin.get() != '\n');
  22.         }
  23.  
  24.         if (!IsIncorrect && (num < MIN || num > MAX))
  25.         {
  26.             IsIncorrect = true;
  27.             cout << "RANGE ERR" << endl;
  28.         }
  29.  
  30.         if (!IsIncorrect && cin.get() != '\n')
  31.         {
  32.             cout << "Err";
  33.             IsIncorrect = true;
  34.             cin.clear();
  35.             while (cin.get() != '\n');
  36.             cout << endl;
  37.         }
  38.     } while (IsIncorrect);
  39.  
  40.     cout << num;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement