Solution to Statistics are often calculated with varying amounts of input data. Write a program that takes … - Sikademy
Author Image

Archangel Macsika

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

The Answer to the Question
is below this banner.

Can't find a solution anywhere?

NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?

Get the Answers Now!

You will get a detailed answer to your question or assignment in the shortest time possible.

Here's the Solution to this Question

#include <bits/stdc++.h> 
#include<vector>
using namespace std;


/*
	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.
*/
int main()
{
	float c=0,temp=0,Max=0,Avg=0;
	c=0;
	cout<<"\n\eEnter Values separated by space: ";
	while(temp>=0)
	{
		cin>>tempif(temp>=0)
		{
			Avg = Avg + temp;
			if(Max<=temp) Max = temp;			
			c++;
		}
	}
	Avg = Avg/c;
	cout<<"\n\tMax. Value = "<<fixed<<setprecision(2)<<Max;
	cout<<"\n\tAverage    = "<<fixed<<setprecision(2)<<Avg;
	return(0);
	
	
}

Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-44-sqid-1038-qpid-34