Hey Fox... i wrote the program for finding the Mean of 4 integers (Thanks to Daniweb members) now im faced to also get the standard deviation of those numbers x=sqrt(X1+X2+X3+X4)/3 here's what i've come up with so far...

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

using namespace std;

int main(void)

{

int X1;
int X2;
int X3;
int X4;
int Sol1;
int Sol2;
double sqrt;

cout<<"Enter The First Integer value:";
cin>>X1;
cout<<"Enter The Second Integer Value:";
cin>>X2;
cout<<"Enter The Third Integer Value:";
cin>>X3;
cout<<"Enter The Forth Integer Value:";
cin>>X4;

{
Sol1=(X1+X2+X3+X4)/4.0;

cout<<"The Result is:";


Sol2=sqrt(double)(X1+X2+X3+X4)/3.0;

cout<<Sol2<<"and"<<Sol2;
}

cin.get();cin.get();

return 0;

}

when i enter the values x1=4,x2=4,x3=4,x4=4 i get the answer 1and1 which doesn't seem right... Any one see where im going wrong....? Thanks

Try it out :)

#include <iomanip>
#include <iostream>
#include <math>


int main(void)

{

int X1;
int X2;
int X3;
int X4;
int Sol1;
double Sol2;


cout<<"Enter The First Integer value:";
cin>>X1;
cout<<"Enter The Second Integer Value:";
cin>>X2;
cout<<"Enter The Third Integer Value:";
cin>>X3;
cout<<"Enter The Forth Integer Value:";
cin>>X4;

{
Sol1=(X1+X2+X3+X4)/4.0;

cout<<"The Result is:";


Sol2=(X1+X2+X3+X4)/3.0;



cout<< Sol1 <<" and " << Sol2 << endl;
}

cin.get();cin.get();

return 0;

}

i fixed the int double
and it gives me 1.3333and1.3333 as answers for the values x1=4,x2=4,x3=4,x4=4
it's calculating the deviation any ideas why it's not working out the mean?

cout<< Sol1 <<" and " << Sol2 << endl; chek your this line ...i did update on this also

commented: Greatt +1

Thanks alot brainfo :) after 9hrs of staring at my screen u saved it bud thx

:)

Er, I think you're just calculating the standard deviation with the wrong formula. Your original post says that:

StdDev = sqrt(X1+X2+X3+X4)/3,

which is not correct. To get the stdDev, you need to calculate the mean, with:

mean = (X1 + x2 + X3 + X4)/4

and then use that to get the standard deviation:

StdDev = sqrt( (X1 - mean)^2 + (X2 - mean)^2 + (X3 - mean)^2 + (X4 - mean)^2 )/3

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.