Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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...

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions