fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <limits>
  4. using namespace std;
  5. int main()
  6. {
  7. int num;
  8. do {
  9. cout << "How many:\n";
  10. cin >> num;
  11. if(!cin)
  12. {
  13. cout << "This wasn't even a number!\n";
  14. cin.clear();
  15. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  16. }
  17. } while (num<1 || num>3);
  18. cout << "You've entered " << num << '\n';
  19. }
  20.  
Success #stdin #stdout 0s 2728KB
stdin
-1
100
foo
5
2
stdout
How many:
How many:
How many:
This wasn't even a number!
How many:
How many:
You've entered 2