Skip to content

Instantly share code, notes, and snippets.

@mattsegura
Created December 5, 2020 21:36
Show Gist options
  • Save mattsegura/90ef108f24ff1384edd2543c122adf31 to your computer and use it in GitHub Desktop.
Save mattsegura/90ef108f24ff1384edd2543c122adf31 to your computer and use it in GitHub Desktop.
simple input validation loop
#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