I have come up with some code and it does not compile.
Error 1 error C2296: ‘^’ : illegal, left operand has type ‘double’
2 IntelliSense: expression must have integral or enum type
The code I was able to come up with is as follows:
#include<iostream>
#include<cmath>
using namespace std;
void getnumbers();
void showmean();
void showdev();
double x1, x2, x3, mean, dev;
void getnumbers()
{
cout<<"Please enter three numbers\n";
cin>>x1,x2,x3;
}
void showmean()
{
mean=(x1+x2+x3)/3;
cout<<"The mean of"<<x1<<", "<<x2<<", "<<x3<<" is "<<mean<<endl;
}
void showdev()
{
dev=sqrt((x1 - mean)^2) + (x2 - mean)^2 + (x3 - mean)^2/3;
cout<<"The standard deviation of"<<x1<<", "<<x2<<", "<<x3<<" is "<<dev<<endl;
}
int main()
{
getnumbers();
showmean();
showdev();
system("pause");
return 0;
}
You can’t take powers like that in C++
std::pow()orx*xfor mathematical x2For multiple inputs it’s
cin >> x1 >> x2 ...etcIn your SD equation, your close paren is in the wrong spot I think, mathematically.
SD = sqrt( (x*x + y*y) / z ). Your close paren makes it x + y*y/3 (or y2/3, forget precedence)