Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ write a function that will accept three values. A user value, the smallest p

ID: 3834531 • Letter: C

Question

C++

write a function that will accept three values. A user value, the smallest possible vlaue and the largest possible value. The function will then determine if that user value is between the smallest and largest value and return a boolean value. True if the user value is between the smallest and largest values. False when it is not. Ex. If I send in 20 , 5, 5 to the function it will return true. If I send 30, 5, 25 to the function then it will return false. IN the main program, you will need to test the returned value and print a message. " number is between smallest and largest values" or " number is not between smallest and largest values"

Include two executions of this function in the main program so that you can execute two tests. One that is valid and one that is not. Ask the user for the range of value (smallest to largest values) along with the user number.

Explanation / Answer

Code:
#include <iostream>
using namespace std;

// function declaration
bool check_uvalue(int, int, int);

int main () {
int user_value, small_value, large_value;

cout << "Enter a user value: ";
cin >> user_value;
cout << "Enter smallest possible value: ";
cin >> small_value;
cout << "Enter largest possible value: ";
cin >> large_value;
// calling a function to see if user value is between smallest and largest value
if(check_uvalue(user_value, small_value, large_value))
cout << "Number is between smallest and largest values" << endl;
else
cout << "Number is not between smallest and largest values" << endl;

return 0;
}

// function returning user value between smallest and largest value
bool check_uvalue(int uvalue, int small, int large) {

if (uvalue > small && uvalue < large )
return 1;
else
return 0;
}

Execution and output:
Enter a user value: 10
Enter smallest possible value: 8
Enter largest possible value: 30
Number is between smallest and largest values

Enter a user value: 50
Enter smallest possible value: 30
Enter largest possible value: 80
Number is between smallest and largest values

Enter a user value: 30
Enter smallest possible value: 5
Enter largest possible value: 25
Number is not between smallest and largest values

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote