fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int askUser(int high, int low = 1);
  7. int askUser();
  8.  
  9. int main()
  10. {
  11. int value = 0;
  12. int number = askUser(15);
  13. cout << "You entered: " << number << "\n\n";
  14.  
  15. number = askUser();
  16. cout << "You entered: " << number << "\n\n";
  17.  
  18. return 0;
  19. }
  20.  
  21. int askUser(int high, int low)
  22. {
  23. int input;
  24. do
  25. {
  26. cout << "Please enter a number" << " (" << low << " - " << high << "): ";
  27. cin >> input;
  28. }
  29. while (input > high || input < low);
  30.  
  31. return input;
  32. }
  33.  
  34. int askUser()
  35. {
  36. int value;
  37. cin >> value;
  38. return(value);
  39. }
Success #stdin #stdout 0s 4196KB
stdin
5
6
stdout
Please enter a number (1 - 15): You entered: 5

You entered: 6