I have this function int GetIntInput(int min, int max)
And I have this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
int GetIntInput(int min, int max)
{
/* Your code goes here
Note: you should call your ValueInRange function to validate the user's input!
This function must also check that the user enters integer data,
and issue an error message and re-prompt the user if they make a mistake. */
int i;
cin >> i;
while (!(ValueInRange(i,min,max)))
{
cout << "Error. Please enter a valid input: ";
cin >> i;
}
return i;
|
So in order to explain it, this is a function in a bigger program. I have to fill out the insides of it with the instructions in the comment.
Right now, I'm able to check using the 'ValuesInRange' function, whether that i that was inputted from the user is between the min and max.
The problem is, I don't know how to check if that i is an integer or not. If the user enters like 4.5, thats an integer! And shouldn't work! But what ends up happening, that 4.5 becomes a 4, and it says like "yes this value 4 is between the min and max".
But it shouldn't do that, it should have a way in the function of checking whether or not its an integer, like 4,5,6 not 4.5 5.4 6.9.
Does anyone know how to do that? Something that I can understand too, not hard so that I can put it in my function.
Thanks