小弟最近刚学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'
希望得到帮助。谢谢。 展开
#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'
希望得到帮助。谢谢。 展开
1个回答
展开全部
#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是<<,有几个写错了
#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是<<,有几个写错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询