I'm working with GCC (g++) on a gentoo linux. I wrote a c++ code to calculate mean, variance and standard deviation from 8 numbers, I feel the code is too long, I also had troube with funct square. sqrt is functioning, but how to get the square of a number. Second thing, how to let the program request, how many numbers to calculate( in this code 8 numbers predefined). Any ideas??

>>>>>>>>>>>>>>>code>>>>>>>>>>>>>>>>>>>>

#include <iostream> using namespace std; int main() { int n , j; double max[8] , _sum=0 , variance; for(n=0;n<=7;n++) { cout << "Type Numbers: " << endl; cin >> max[n]; } n=0; cout << endl; for(j=0;j<=7;j++) { cout << max[n] << endl; _sum=_sum+max[n]; n++; } double mean = _sum/(n); cout << endl << "The Sum is: " << _sum; cout << endl << "The mean is: " << mean; n=0; j=0; _sum=0; for(j=0;j<=7;j++) { max[n]=(max[n]-mean) * (max[n]-mean); _sum=_sum+max[n]; n++; } variance=_sum/(n-1); cout << endl << "Variance is: " << variance; cout << endl << "Standard Deviation is: " << sqrt(variance) << endl; cout << endl; }

>>>>>>>>>>>>code>>>>>>>>>>>>>>>>>

many thanks, friends

Rolf