C++求救!程序输入1,2,3后出现警告框,求问什么意思??
1.求一元二次方程ax2+bx+c=0的根,其中a、b、c为实数,由键盘输入。源程序:#include<iostream>usingnamespacestd;voidma...
1. 求一元二次方程ax2+bx+c=0的根,其中a、b、c为实数,由键盘输入。
源程序:
#include <iostream>
using namespace std;
void main()
{double a,b,c,d,x1,x2;
cout<<"请输入a,b,c"<<endl;
cin>>a>>b>>c;
d=b*b-4*a*c;
if(d<0)
cout<<"no definition"<<endl;
else
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
cout<<"该二元一次方程的根分别为"<<x1<<endl;
cout<<" "<<x2<<endl;
}
还有
求改错.......
#include <iostream>
using namespace std;
void main()
{double x,y;
cout<<"请输入自变量x"<<endl;
cin>>x;
if(x<1)
{ y=x;
cout<<"函数值y="<<y<<endl;
else
if(x>=1&x<10)
y=2x-1;
cout<<"函数值y="<<y<<endl;
else
y=3x-11;
cout<<"函数值y="<<y<<endl;} 展开
源程序:
#include <iostream>
using namespace std;
void main()
{double a,b,c,d,x1,x2;
cout<<"请输入a,b,c"<<endl;
cin>>a>>b>>c;
d=b*b-4*a*c;
if(d<0)
cout<<"no definition"<<endl;
else
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
cout<<"该二元一次方程的根分别为"<<x1<<endl;
cout<<" "<<x2<<endl;
}
还有
求改错.......
#include <iostream>
using namespace std;
void main()
{double x,y;
cout<<"请输入自变量x"<<endl;
cin>>x;
if(x<1)
{ y=x;
cout<<"函数值y="<<y<<endl;
else
if(x>=1&x<10)
y=2x-1;
cout<<"函数值y="<<y<<endl;
else
y=3x-11;
cout<<"函数值y="<<y<<endl;} 展开
1个回答
展开全部
都是复合语句问题,想要if 或者else 执行多个语句必须加大括号
#include <iostream>
#include<cmath>
using namespace std;
void main()
{ double a,b,c,d,x1,x2;
cout<<"请输入a,b,c"<<endl;
cin>>a>>b>>c;
d=b*b-4*a*c;
if(d<0)
cout<<"no definition"<<endl;
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
cout<<"该二元一次方程的根分别为"<<x1<<endl;
cout<<" "<<x2<<endl;
}
}
#include <iostream>
using namespace std;
void main()
{
double x,y;
cout<<"请输入自变量x"<<endl;
cin>>x;
if(x<1)
{
y=x;
cout<<"函数值y="<<y<<endl;
}
else if(x>=1&&x<10)
{
y=2*x-1;
cout<<"函数值y="<<y<<endl;
}
else
{
y=3*x-11;
cout<<"函数值y="<<y<<endl;
}
}
#include <iostream>
#include<cmath>
using namespace std;
void main()
{ double a,b,c,d,x1,x2;
cout<<"请输入a,b,c"<<endl;
cin>>a>>b>>c;
d=b*b-4*a*c;
if(d<0)
cout<<"no definition"<<endl;
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
cout<<"该二元一次方程的根分别为"<<x1<<endl;
cout<<" "<<x2<<endl;
}
}
#include <iostream>
using namespace std;
void main()
{
double x,y;
cout<<"请输入自变量x"<<endl;
cin>>x;
if(x<1)
{
y=x;
cout<<"函数值y="<<y<<endl;
}
else if(x>=1&&x<10)
{
y=2*x-1;
cout<<"函数值y="<<y<<endl;
}
else
{
y=3*x-11;
cout<<"函数值y="<<y<<endl;
}
}
追问
错误 1 error C2556: “void main(void)”: 重载函数与“int main(void)”只是在返回类型上不同 c:\users\administrator\desktop\c++实验\实验作业\12314\12314\124.cpp 23 1 12314
追答
你不会把两个程序写在一起或者一起打开吧,这样是不行的。你用的是什么编译器?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询