How to get code to keep repeating until a value is entered correctly?

Hey, could someone help me out with this?

1
2
3
4
5
6
7
	while (number > min && number < max)
	{
		if (number > min && number < max)
			return number;
		else
			cout << "Out of range. Try again:" << endl;
	}
The usual idiom for this is a do while loop.
1
2
3
4
5
6
7
8
9
10
11
12
int get_number (int min, int max)
{   int number;
    
    do  
	{   cout << "Enter a number between " << min << " and " << max;
	    cin >> number;
	    if (number < min || number > max)
    		cout << "Out of range. Try again:" << endl;
	}
    while (number < min || number > max);
    return number;
}    
Topic archived. No new replies allowed.