Hi! I'm creating a program which has a section that the user is prompted to input a number. The number has to be from 1-10 or the program loops an error message which prompts the user to re-enter an input. Once the user enters a valid number from 1-10, the program then proceeds.
The actual validation that the number is 1-10 takes place in a separate function, titled "int validate". This function is called from "int main" like so:
1 2 3 4 5 6
system("CLS");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n"
<< "\t\t Please enter a number from 1-10: ";
cin >> number;
validate(number);
and the actual code inside int validate is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int validate(int number)
{
//loop until a valid score is entered...
while (number < 1 || number > 4)
{
system("CLS");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout << "\t\t\t\t ";
cout << number << " is invalid!";
cout << "\n\t\t Please enter a value in the range 1-10: ";
cin >> number;
cout << "\n\n\n\n\n\t\t";
}
}
What ends up happening, however, is that the user's first input from int main will be remembered. Even though int validate will go on forever until the user enters something from 1-10, the program will continue to run as if that never happened, and it just responds to the first (can be invalid) input.