小弟最近刚学C++。在VC++6.0环境下编写了一个求2元一次方程的程序。但是在编译的时候报错。

#include<iostream>;#include<math.h>;usingnamespacestd;intmain(){doublea,b,c,x1,x2;cou... #include<iostream>;
#include<math.h>;
using namespace std;

int main()
{
double a, b,c,x1,x2;
cout<<"请输入ax*x+bx+c=0中的a,b,c值"<<endl;
cout<<"a:"<<endl;
cin<<a;
cout<<"b:"<<endl;
cin<<b;
cout<<"c:"<<endl;
cin<<c;
if((b*b-4*a*c)<0)
{
cout<<"方程无解"<<endl;
}
else if((b*b-4*a*c)==0)
{
x1=-b/2a;
cout<<"方程有唯一解:"<<x1<<endl;
}
else if((b*b-4*a*c)>0)
{
x1=(-b+sqrt(b*b-4*a*c))/2a;
x2=(-b-sqrt(b*b-4*a*c))/2a;
cout<<"方程有解:"<<"x1="<<x1<<"x2="<<x2<<endl;
}
return 0;
}

c:\documents and settings\du\桌面\c\c++ primer\5\cc.cpp(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(10) : error C2676: binary '<<' : 'class std::basic_istream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(12) : error C2676: binary '<<' : 'class std::basic_istream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(14) : error C2676: binary '<<' : 'class std::basic_istream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(21) : error C2059: syntax error : 'bad suffix on number'
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(21) : error C2146: syntax error : missing ';' before identifier 'a'
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(26) : error C2059: syntax error : 'bad suffix on number'
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(26) : error C2146: syntax error : missing ';' before identifier 'a'
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(27) : error C2059: syntax error : 'bad suffix on number'
C:\Documents and Settings\Du\桌面\C\C++ Primer\5\cc.cpp(27) : error C2146: syntax error : missing ';' before identifier 'a'

希望得到帮助。谢谢。
展开
 我来答
iwlyx
2012-06-10 · TA获得超过4825个赞
知道大有可为答主
回答量:5599
采纳率:50%
帮助的人:4778万
展开全部
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
double a, b,c,x1,x2;
cout<<"请输入ax*x+bx+c=0中的a,b,c值"<<endl;
cout<<"a:"<<endl;
cin>>a;
cout<<"b:"<<endl;
cin>>b;
cout<<"c:"<<endl;
cin>>c;
if((b*b-4*a*c)<0)
{
cout<<"方程无解"<<endl;
}
else if((b*b-4*a*c)==0)
{
x1=-b/2*a;
cout<<"方程有唯一解:"<<x1<<endl;
}
else if((b*b-4*a*c)>0)
{
x1=(-b+sqrt(b*b-4*a*c))/2*a;
x2=(-b-sqrt(b*b-4*a*c))/2*a;
cout<<"方程有解:"<<"x1="<<x1<<"x2="<<x2<<endl;
}
return 0;
}
改完了,主要是cin是>>,cout是<<,有几个写错了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式