Hey guys im trying to write a code to give me Arthimetic mean and standard deviation for 4 Integer values... i don't know what im doing wrong it's not letting me compile any ideas??

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

using namespace std;

int main(void)

{

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

cout<<"---*******Arthimetic Mean And Standard Deviation Calculator*******---";
cout<<"\n\nEnter 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;


Sol2=sqrt(X1 - mean)^2  + (X2 - mean)^2 + (X3 - mean)^2 + (X4 - mean)^2 /3.0;



cout<<"\n\nThe Arthimetic Mean is:"<< Sol1 <<"\n\n and " <<"\n\nThe Standard Deviation is:"<<Sol2 << endl;
cout<<"\n\n\n*********************End Of Calculation************************";

}

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

return 0;

}

On line 32 you are using mean without ever initializing it.

:/ i thought i declared it already

Can someone review the code for me please

There are several errors. The biggest one is to write (X2 - mean)^2 since the ^2 does not mean power, but actually means xor.

If you want power, you have to write either pow(value,2.0) or you could of course do value*value.

Note that you don't initialize mean, and mean is declared as an integer, this is not a good idea, since the average is unlikely to be an integer. E.g. 1,1,2,2 the average is 1.5

Sol1 is actually your average (as you calculated it)

There are several errors. The biggest one is to write (X2 - mean)^2 since the ^2 does not mean power, but actually means xor.

If you want power, you have to write either pow(value,2.0) or you could of course do value*value.

Note that you don't initialize mean, and mean is declared as an integer, this is not a good idea, since the average is unlikely to be an integer. E.g. 1,1,2,2 the average is 1.5

Sol1 is actually your average (as you calculated it)

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

using namespace std;

int main(void)

{

int X1;
int X2;
int X3;
int X4;
int Sol1;
int Sol2;
float mean;


cout<<"---*******Arthimetic Mean And Standard Deviation Calculator*******---";
cout<<"\n\nEnter 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;


Sol2=sqrt(X1 - mean)*2 + (X2 - mean)*2 + (X3 - mean)*2 + (X4 - mean)*2/3.0;



cout<<"\n\nThe Arthimetic Mean is:"<< Sol1 <<"\n\n and " <<"\n\nThe Standard Deviation is:"<<Sol2 << endl;
cout<<"\n\n\n*********************End Of Calculation************************";

}

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

return 0;

}

ok i changed a few things following what you said... it compiles now but then tells me The variable 'mean' is being used without being initialized.
I declared it as a floating number.

Member Avatar for MonsieurPointer

Declaring a variable and initializing it are two different things. This declares mean:

float mean;

But this initializes it:

float mean = 0.0;

This works, too:

float mean;
mean = 0.0;

Also, are you sure this is correct?

Sol2=sqrt(X1 - mean)*2 + (X2 - mean)*2 + (X3 - mean)*2 + (X4 - mean)*2/3.0;

Make sure that those parentheses are placed correctly...

Declaring a variable and initializing it are two different things. This declares mean:

float mean;

But this initializes it:

float mean = 0.0;

This works, too:

float mean;
mean = 0.0;

Also, are you sure this is correct?

Sol2=sqrt(X1 - mean)*2 + (X2 - mean)*2 + (X3 - mean)*2 + (X4 - mean)*2/3.0;

Make sure that those parentheses are placed correctly...

Oh Thanks alot man. And everybody else who helped.

Float deals in 1.2 and numbers in POINT values.. that's why u were having the problem in this code..!!

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.