fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int r = -1;
  7. int c = -1;
  8. bool valid = false;
  9. do
  10. {
  11. cout<<"Insert coordinates: ";
  12. if (cin >> r >> c)
  13. {
  14. if (r >= 0 && r <= 10 && c >= 0 && c <= 10)
  15. {
  16. valid = true;
  17. }
  18. }
  19. else
  20. {
  21. cin.clear();
  22. cin.ignore();
  23. }
  24.  
  25. if (!valid)
  26. {
  27. cout << "ERROR: Number of row and column must be an integer between 0 and 10." << endl;
  28. }
  29. } while (!valid);
  30.  
  31. cout << "You entered (" << r << ", " << c << ")" << endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 3300KB
stdin
11 12 a b 1 5
stdout
Insert coordinates: ERROR:  Number of row and column must be an integer between 0 and 10.
Insert coordinates: ERROR:  Number of row and column must be an integer between 0 and 10.
Insert coordinates: ERROR:  Number of row and column must be an integer between 0 and 10.
Insert coordinates: You entered (1, 5)