C++菜鸟求救!!! VS2010
#include<iostream>
#include<string>
using namespace std;
int main()
{
float x,y;
cout<<"请输入一个数值:";
cin>>x;
if(x>=0)
{
cout<<"该数值的绝对值为:"<<x<<end;(最后一个"<<"上提示"没有与这些操作数匹配的"<<"运算符")
}
else
cout<<"该数值的绝对值为:"<<y=-x<<endl;(负号上提示"表达式必须包含整数或者枚举类型";"endl"上提示无法确定需要哪个重载函数"endl"实例)
return 0;
}
我把y=-x弄到前一行去,endl上面就没有错误提示了.
[解决办法]
#include<iostream>
#include<string>
using namespace std;
int main()
{
float x,y;
cout<<"请输入一个数值:";
cin>>x;
if(x>=0)
{
cout<<"该数值的绝对值为:"<<x<<endl;//(最后一个"<<"上提示"没有与这些操作数匹配的"<<"运算符")
}
else
cout<<"该数值的绝对值为:"<<-x<<endl;//负号上提示"表达式必须包含整数或者枚举类型";"endl"上提示无法确定需要哪个重载函数"endl"实例)
return 0;
}
这样不就好了啊!哪行有问题就该哪行啊!
[解决办法]
- C/C++ code
#include<iostream>#include<string>using namespace std;int main(){ float x,y; cout<<"请输入一个数值:"; cin>>x; if(x>=0) { cout<<"该数值的绝对值为:"<<x<<endl;//哥们,是endl.不是end. } else { cout<<"该数值的绝对值为:"<<-x<<endl;//y=-x是一条赋值语句,没有返回值,所以不能输出。 } return 0;}
[解决办法]
第一个ednl不知道是不是你打错了,你的代码是end;后面第二个输出应该是-x,不是y=-x。