Question: 4.15 LAB: Varied amount of input data Statistics are often calculated with varying amounts of input data. Write a program that takes any number of

4.15 LAB: Varied amount of input data

Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the max and average. A negative integer ends the input and is not included in the statistics. Assume the input contains at least one non-negative integer.

Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout << fixed << setprecision(2); once before all other cout statements.

Ex: When the input is:

15 20 0 3 -1 

the output is:

20 9.50

#include #include using namespace std;

int main() {

int num; int count=0; double sum=0; double max=0; cout<< fixed << setprecision(2)<<; do { cin >> num; if (num >= 0) { count++; sum += num; if (num > max) max = num; } } while (num >= 0); cout << max << " " << sum/count << endl;

return 0; }

Latest submission - 3:25 PM PST on 03/05/23

Total score: 0 / 10

Only show failing tests

Download this submission

1:Compare outputkeyboard_arrow_up

0 / 3

Output differs. See highlights below. Special character legend

Input

15 20 0 3 -1

Your output

20 9.5 20.00

Expected output

20 9.50

2:Compare outputkeyboard_arrow_up

0 / 3

Output differs. See highlights below. Special character legend

Input

2 2 2 2 12 0 8 3 -5

Your output

12 3.875 12.00

Expected output

12 3.88

3:Compare outputkeyboard_arrow_up

0 / 2

Output differs. See highlights below. Special character legend

Input

5 -1

Your output

5 5 5.00

Expected output

5 5.00

4:Compare outputkeyboard_arrow_up

0 / 2

Output differs. See highlights below. Special character legend

Input

0 -1

Your output

0 0 0.00

Expected output

0 0.00

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!