Hey guys Ive been working on this problem for standard deviation, and so far ive got it all right accept my declaration in this module, was wondering if anyone can help me see whats wrong with my formula or the decelerations i have made
Here is the code for my function:

double findStdDev(double x1, double x2, double x3, double x4, double x5)
                 
{
double sDev,x;
x=1;
sDev=sqrt((x1-pow(x,2))+(x2-pow(x,2))+(x3-pow(x,2))+(x3-pow(x,2))+(x4-pow(x,2))+(x5-pow(x,2)));
return sDev; 
	
}

I'm assuming x1 thru x5 are your data points?

The definition of the standard deviation involves first finding the mean of the values.
Then find the variance by summing (the difference between data point i and the mean)^2 divided by either the number of values (for an entire population) or number of values - 1 for a sample.
What constitutes a population is debatable and so you probably have a sample.
Taking the square root of the variance gets you the standard deviation.

Some p-code:

double total;
for loop to find the total of the data points

double average = total/ 5;
double totaldev;

for loop over the data points again
      totaldev += pow((data i - average),2);

sDev = sqrt(totaldev/4);

(obviously I've hardcoded the N values based on the number of parameters you pass in)

Wow i just realized that as i went online to check the fourm, thanks :-P

Ok nevermind i thought i had this going right and im getting a funny number as an answer to the standard deviation. heres the code got so far

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double findMean(double x1, double x2, double x3,
                double x4, double x5);

double findStdDev(double x1, double x2, double x3,
				  double x4, double x5,double x);
 
int main()
{
  
	double x1, x2, x3, x4, x5;
	double mean, stdDev; 

   


		cout << "Please Enter 5 numbers" << endl; 
		cin >> x1;
		cin >> x2;
		cin >> x3;
		cin >> x4;
		cin >> x5; 
		 
		mean=findMean( x1, x2, x3, x4, x5);

  
		stdDev=findStdDev( x1, x2, x3,x4, x5,mean);
   cout << fixed << showpoint << setprecision(2); // Format expected input
   cout << "The mean is : " << mean << endl; 
cout << "The Standard Deviation is : " << stdDev << endl;
   
}

double findMean(double x1, double x2, double x3, double x4, double x5)
{
	double mean; 
	mean=(x1+x2+x3+x4+x5)/5; 
return mean; 

}

 double findStdDev(double x1, double x2, double x3, double x4, double x5,double x)
                 
{
double sDev;

sDev=sqrt((x1-pow(x,2))+(x2-pow(x,2))+(x3-pow(x,2))+(x4-pow(x,2))+(x5-pow(x,2))/5);
return sDev; 
	
}

Okay, so you have a mean now, but you're still not applying the pow stuff right. Again look at the theory, you are averaging the amount of variation of each point from the mean, squared and taking the square root of it. So it's going to be pow(x1-x,2)+pow(x2-x,2) + etc.

Ok nevermind i thought i had this going right and im getting a funny number as an answer to the standard deviation. heres the code got so far

double findStdDev(double x1, double x2, double x3, double x4, double x5,double x)
                 
{
double sDev;

sDev=sqrt((x1-pow(x,2))+(x2-pow(x,2))+(x3-pow(x,2))+(x4-pow(x,2))+(x5-pow(x,2))/5);
return sDev; 
	
}

in your calculation, you need to change
( xN - pow(x,2) )
to
pow( xN - x , 2 )

How can I get the sum and variance from here now?

any help

any help

You need to show us your code, I finnaly got it to work :-) on mine. Sadly I believe im the only one in my class. My teacher is a real moron she just picks random problems out of the book that have functions, and reserve words we never heard of yet. And to make matters worse she just even bother to solve them and have a solution ready to grade ours. Most of the time she doesnt even figure it out on her own X( Anyway show us your code and we can go from there.

any help

Sum
Variance
Perhaps try to help yourself some. There is this really great resource for programmers to find information to help solve their problems. It's called google.

commented: Nice +19
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.