我已经提出了一些代码而且它没有编译.
错误1错误C2296:'^':非法,左操作数类型为'double'2
智能感知:表达式必须具有整数或枚举类型
我能想出的代码如下:
#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;
}
Run Code Online (Sandbox Code Playgroud)
你不能在C++中采取这样的权力
std::pow()或x*x用于数学x 2对于多个输入,它是 cin >> x1 >> x2 ...etc
在你的SD方程中,我认为你的近距离在数学上是错误的.
SD = sqrt( (x*x + y*y) / z ).你的近距离使它成为x + y*y/3(或y 2/3,忘记优先)