Question

Write a function named midvalue that is passed three unique int values and returns the one...

Write a function named midvalue that is passed three unique int values and returns the one that is in the middle. Thus, midvalue(5,28,14) returns 14. ( in c++)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I am providing the answer for the above question:

Code:

#include <bits/stdc++.h>
using namespace std;
  
int midvalue(int , int , int ); //funtion declaration
  
int main()
{
cout <<"midvalue:"<<midvalue(5,28,14);  
return 0;
}

int midvalue(int x, int y, int z)
{
//if y is greater than x and less then z (or) y is greater than z and less than x
if ((x < y && y < z) || (z < y && y < x))
return y;
//if x is greater than y and less then z (or) x is greater than z and less than y
else if ((y < x && x < z) || (z < x && x < y))
return x;
else
return z;
}
Screenshot of code:

#include <bits/stdc++.h> using namespace std; int midvalue(int , int , int ); int main() cout <<midvalue:<<midvalue(5,28,14

Output:

midvalue:14

Hoping that the above answer will help you...Thank you...

Add a comment
Know the answer?
Add Answer to:
Write a function named midvalue that is passed three unique int values and returns the one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a static method named middleValue that takes three int arguments, and returns an int. When...

    Write a static method named middleValue that takes three int arguments, and returns an int. When given three different argument values, the method should return the value that is numerically between the other two values. When given three values where two or more argument values are the same, then the function should return that value. Examples: middleValue(1, 2, 3) will return 2 middleValue(5, 2, 7) will return 5 middleValue(8, 4, 6) will return 6 middleValue(1, 2, 1) will return 1...

  • Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...

    Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...

  • Using swift 4.0, Write a function (not method) named findName which returns a given name (passed...

    Using swift 4.0, Write a function (not method) named findName which returns a given name (passed as a parameter) if it is in the string array passed as a parameter, otherwise return nil Demonstrate calling the function findName. Using swift 4.0

  • A void function named getInventory is passed four int variables named beginInv, sales, purchases, and endInv....

    A void function named getInventory is passed four int variables named beginInv, sales, purchases, and endInv. The function’s task is to calculate the ending inventory, using the beginning inventory, sales, and purchase amounts passed to the function. The function should store the result in the endInv variable. Which of the following function headers is correct? a. void getInventory(int b, int s, int p, int &e) b. void getInventory(int b, int s, int p, int e) c. void getInventory(int &b, int...

  • A void function named getInventory is passed four int variables named beginInv, sales, purchases, and endInv....

    A void function named getInventory is passed four int variables named beginInv, sales, purchases, and endInv. The function’s task is to calculate the ending inventory, using the beginning inventory, sales, and purchase amounts passed to the function. The function should store the result in the endInv variable. Which of the following function headers is correct? a. void getInventory(int b, int s, int p, int &e) b. void getInventory(int b, int s, int p, int e) c. void getInventory(int &b, int...

  • Write a function named maxNumber. You are given 2 positive int values, a, and b. Your...

    Write a function named maxNumber. You are given 2 positive int values, a, and b. Your function should return the larger value that is in range 10…. 20 inclusive. Else return 0 if neither is in the range. Example maxNumber(11,19) returns 19 maxNumber (10,45) return 10. maxNumber (30,45) returns 0. Please use an if function and provide an explanation. Thank you!!!

  • In Python: Write the definition for a function named avg which accepts two int parameters, and...

    In Python: Write the definition for a function named avg which accepts two int parameters, and returns the average of the two values Write a statement that calls this function to print out the average of values 11 and 25.

  • 4. Write a static method named ConcatStrings that is passed any number of parameters of   type...

    4. Write a static method named ConcatStrings that is passed any number of parameters of   type String, and returns a single string that is the concatenation of the strings passed.   (4 pts.)   5. Write a static method named ConcatObjects that is passed any number of parameters of   type Object, and returns a single string that is the concatenation of the result of the call to   toString() for each of the objects. (4 pts.)   6. Write a class named Triplet that...

  • Problem H1 (Using C++) In the main function, define four variables of type int, named: first,...

    Problem H1 (Using C++) In the main function, define four variables of type int, named: first, second, third, and total. Write a function named getData that asks the user to input three integers and stores them in the variables first, second, and third which are in the main function. Write a function named computeTotal that computes and returns the total of three integers. Write a function named printAll that prints all the values in the format shown in the following...

  • Question 14; Write a C function named isSymmetric, the prototype of which is given below, that...

    Question 14; Write a C function named isSymmetric, the prototype of which is given below, that returns 1 if the elements of an array of integers named myArray of size n are symmetric around the middle. If the array elements are not symmetric, the function should return 0. Both the array and its size are specified as parameters. (10 marks) Clue: Array myArray of size n is symmetric if myArray[0] is equal to myArray[n-1], myArray[1] is equal to myArray[n-2], and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT