1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
using std::cout;
using std::cin;
void prompt(const char *str, int &data, int min, int max)
{
const static char error[] = "That is not an option\n",
buffer[] = "==================\n";
cout<<buffer;
do{
cout<<str;
cin>>data;
cin.clear(); //Clears errors flags: cin
cin.ignore(1000,'\n'); //Flush cin buffer
}while((data<min || data>max) && cout<<error);
}
int main()
{
int gender, ageGroup, timeStandard, event, time;
prompt("\nWhat gender (1-2): ",gender,1,2);
prompt("\nWhat age group (1-5): ",ageGroup,1,5);
prompt("\nWhat time standard (1-5): ",timeStandard,1,5);
prompt("\nWhat event (1-5): ",event,1,5);
prompt("\nWhat time (1-5): ",time,1,5);
cout<<"Press <enter> to exit console: ";
cin.get();
return 0;
}
|
==================
What gender (1-2): 3
That is not an option
What gender (1-2): 2
==================
What age group (1-5): 6
That is not an option
What age group (1-5): 4
==================
What time standard (1-5): 2
==================
What event (1-5): 3
==================
What time (1-5): 1
Press <enter> to exit console: |