Advertisement
IMustRemainUnknown

Error Handling (int)

Oct 21st, 2022
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int num;
  7.    
  8.     while(num < 1 or num >3){
  9.         cout << "Type any number within 1-3: ";
  10.        
  11.         if (!(cin >> num)){
  12.             cin.clear();
  13.             cin.ignore();
  14.             cout << "\nError!";
  15.         }
  16.  
  17.     }
  18.     return 0;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement