Advertisement
avr39ripe

cppRangedInputExample

Jun 23rd, 2021
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     const int minRange{ 0 };
  6.     const int maxRange{ 10 };
  7.     bool incorrect{ true };
  8.     int num{};
  9.  
  10.     do
  11.     {
  12.         std::cout << "Enter number from " << minRange << " to " << maxRange << '\n';
  13.         std::cin >> num;
  14.        
  15.         incorrect = (num < minRange and num > maxRange);
  16.  
  17.         if (incorrect)
  18.         {
  19.             std::cout << "Wrong input!\nTry again!\n";
  20.         }
  21.  
  22.     } while (incorrect);
  23.            
  24.     std::cout << "Good number is: " << num << '\n';
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement