我想出了一些代码,但它无法编译。
错误 1 错误 C2296:“^”:非法,左操作数的类型为“双”
2 IntelliSense:表达式必须具有整数或枚举类型
我能够想出的代码如下:
#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;
}