fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. bool valid=false;
  8. int road;
  9.  
  10. while (!valid) {
  11. string line;
  12. cout << "how long is the road in meters " << endl;
  13. getline(cin, line);
  14. valid = true;
  15. stringstream sst(line);
  16. sst>>road;
  17. if ((sst.fail()) || ((road > 250) || (road < 0)))
  18. {
  19. cout << "Please enter an Integer which is between 0 and 250." << endl;
  20. valid = false;
  21. }
  22. }
  23. cout <<road;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3464KB
stdin
abc 
100
stdout
how long is the road in meters 
Please enter an Integer which is between 0 and 250.
how long is the road in meters 
100