Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int InputInt(int lowestVal, int highestVal)
  6. {
  7.     int input;
  8.     cin >> input;
  9.     while(input < lowestVal || input > highestVal)
  10.     {
  11.         cout << "Wrong input, make sure it is between " << lowestVal << " and " << highestVal << ":";
  12.         cin >> input;
  13.     }
  14.     return input;
  15. }
  16.  
  17. int main()
  18. {
  19.     int num1, num2;
  20.     cout << "Input 2 numbers to add between 1 and 10: ";
  21.     num1 = InputInt(1, 10);
  22.     num2 = InputInt(1,10);
  23.     cout << "Result is: " << num1+num2 << endl;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement