write a functioun called GetIntegerIn Range. this function takes one argument: a
ID: 3567292 • Letter: W
Question
write a functioun called GetIntegerIn Range. this function takes one argument: an integer that represents an upper bound, the largest possible value that user will be asked to enter . the function returns an integer. the function should prompt the user to enter an integer value between 0 and passed in argument inclusive. as long as a value that lies outside the range is entered display an error menage and prompt the user for another value once a valid value is entered it should be returned to the cling function
Explanation / Answer
int getIntegerInRange(int upper){
int num;
while(1){
cout << "Enter a value between 0 and " << upper << ": ";
cin >> num;
if(num >= 0 && num <= upper){
return num;
}
cout << "Invalid Input try again! ";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.