Question: Write a complete C++ program that does the following. First it reads three integers and reports the median of those three integers. Next, it reads

Write a complete C++ program that does the following.

  1. First it reads three integers and reports the median of those three integers.

  2. Next, it reads integers until it reads 1. It reports the mean of all of those integers, excluding the 1 at the end.

Example 1

If the input is

 3 9 5 4 5 8 20 25 -1 

then your program should say:

 The median of (3, 9, 5) is 5. The mean of (4, 5, 8, 20, 25) is 12.40

Using

Create integer variables x, y and z

 int x, y, z; 

Create a real-valued variable r

 double r; 

Read an integer and store it into x

 scanf("%i", &x); 

Read three integers and store them into x, y and z

 scanf("%i%i%i", &x, &y, &z); 

Read an integer and store it into x

 scanf("%i", &x); 

Write a string

If x = 4, y = 10, z = 3 and median = 4, then

 printf("The median of %i, %i and %i is %i. ", &x, &y, &z, &median); 

writes

The median of 4, 10 and 3 is 4. 

Write an integer

 printf("%i", x); 

Write a real number

If r has type double, then

 printf("%0.2lf", r);

If-statement with else

 if(x > y & y > z) {  } else {  } 

If-statement without else

 if(x > y & y > z) {  } 

While-loops

 while(x != -1) {  } 

Main function

 int main() { ... return 0; } 

___________________________________________________

What I have so far...

Write a complete C++ program that does the following. First it reads

#include using namespace std; int count = 0; int total = 0; int x, y, z; double avg; scanf("%i",&x); if(x > y & y > Z) else while (X!=-1) total = total + X count = count + 1; scanf("%", &x); avg = total/count; printf("%0.21f", avg)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!