Created
December 5, 2020 21:36
-
-
Save mattsegura/90ef108f24ff1384edd2543c122adf31 to your computer and use it in GitHub Desktop.
simple input validation loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
const int min_num = 10, | |
max_num = 25; | |
int number; | |
cout << "\nEnter a number in the range of 10 through 25: "; | |
cin >> number; | |
while (number < min_num || number > max_num) | |
{ | |
cout << "Your number cannot be less than " << min_num | |
<< " or greater than " << max_num << "\nEnter your number again: "; | |
cin >> number; | |
} | |
cout << "Nice, input validation concluded\n"; | |
cout << "Your number is " << number; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment