Question: Create the getInt function following these requirements: Input: a string prompt, an integer minimum value, and an integer maximum value. Output: Returns an integer the
Create the getInt function following these requirements:
Input: a string prompt, an integer minimum value, and an integer maximum value.
Output: Returns an integer the user entered.
Side effects: Displays the prompt, gets input from the user, and may display error messages and reprompt the user as needed.
Create a Boolean value to tell you if you have a valid value to return. Initialize it to false.
Create an integer variable to store the user input.
While you do not have a valid value to return do the following:
Prompt the user to enter a value.
Read an integer value in from the user.
If that read did not cause an error then:
If the value is less than the minimum, display an appropriate error message.
If the value is greater than the maximum, display an appropriate error message.
If the value is within range, set the Boolean value to indicate we have valid input.
Otherwise, display an error message that an invalid integer has been entered, clear cin's error flags, and clear the input buffer.
Return the user input.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
