I have created a function in C that tests if an integer in between a range of 100 (min) and 500 (max) - The function calls on another function called "getInt()" which tests whether the integer is valid - this part is working fine. My issue is that the when I test, the while loop only runs once - I enter a value not within the range and I get the correct error message and prompt to re-enter - When I enter another value, the program just stops. I am only posting the function code here as the code in the main is correct (was supplied by my college):
int getIntInRange(int min, int max) { int intValue = 0; int flag = 0;
while (flag ==0) {
intValue = getInt();
if (intValue < min) {
printf("*** OUT OF RANGE*** <Enter a number between %d and %d>: ", min, max);
clearKeyboard();
}
else if (intValue > max) {
printf("*** OUT OF RANGE*** <Enter a number between %d and %d>: ", min, max);
clearKeyboard();
}
else {
flag = 1;
}
}
return intValue;