【发布时间】:2012-10-09 17:17:45
【问题描述】:
我想出了一些代码,但它无法编译。
错误 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;
}
【问题讨论】:
-
(我认为你的 cin 语法是错误的,但我可能是错的,因为我不知道你在问什么)
-
@Collin 代码不执行。 Visual Studio 2010 的错误列表中的错误列在问题的顶部。现已编辑
-
我想他想知道为什么 C++ 中的按位 XOR 运算符不能用作指数运算符。肯定会编译的。但是....
-
@WhozCraig 不,代码对我来说看起来不错,但平方根函数给我带来了压力
-
您只是发布了您的代码并询问为什么它无法编译。对于 StackOverflow,这不是一个合适的问题。
标签: c++