Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with statistical analysis assignment

Status
Not open for further replies.

clip123

Technical User
Feb 10, 2002
10
0
0
US
Write program to display sum,mean,variance, and std deviation of an unknown number of numbers that does not exceed 20.

(The output should look like this:)
I will give you the sum, mean, and std dev of any series of numbers.

How many numbers will you enter (up to 20)? 7

Type each number, followed by the enter key.
Enter Number 1: 12
Enter Number 2: 22
Enter Number 3: 34
Enter Number 4: 43
Enter Number 5: 45
Enter Number 6: 54
Enter Number 7: 99

You have entered the following:
12 22 34 43 45
54 99

The sum is 309
The mean is 44.1429
The variance is 789.1436
The std dev is 28.0917

My question is:
1) How do you make it so that if the user enters more than 20 numbers that it will display a message and proceed to generate the data and the calculated values.

2)Calculate the variance

3)How do you make it so that when you print out the numbers that were entered that they will be displayed 5 numbers to a line.


 
This is what i have so far and i know that the variance part is wrong.

#include <iostream>
#include <cmath>
using namespace std;

int main ( )
{

int x[20]={0};
int count, n=0;
float sum=0, mean=0;
double variance=0, StandardDeviation;

cout << &quot;I will give you the sum, mean, variance and standard deviation &quot;
<< &quot;\nof an unknown number of numbers that does not exceed 20.&quot; <<endl;

cout << &quot;\nHow many numbers will you enter (up to 20)? &quot; << &quot; &quot;;
cin >> n;

cout << &quot;\nType each number, followed by the enter key.&quot; << endl;

for(count=0;count<=n-1; count++)
{
cout << &quot;Enter Number &quot; << count+1 << &quot;: &quot;;
cin >> x[count];
sum += x[count];
}

cout << &quot;\nYou have entered the following: &quot; << endl;

for(int counts=0; counts<=n-1; counts++)
{

cout << x[counts] << &quot; &quot;;
}

cout << endl;

cout << &quot;\nThe sum is &quot; <<sum<<endl;
mean = sum/n;
cout << &quot;\nThe mean is &quot; <<mean<<endl; variance=((counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean) +(counts-mean)*(counts-mean)
+(counts-mean)*(counts-mean))/n-1;
cout <<&quot;\nThe variance is &quot; << variance;
StandardDeviation=sqrt(variance);
cout << &quot;\n\nThe standard deviation is &quot; <<StandardDeviation <<endl;
return 0;
} // end main
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top