C++为什么总是提示没有if匹配的非法else
#include<stdio.h>#include<math.h>intmain(){doublea,b,c,d,e,x,x1,x2;printf("请输入a,b,c")...
#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c,d,e,x,x1,x2;
printf("请输入a,b,c");
scanf("%d,%d,%d",&a,&b,&c);
if (a==0);
{
printf("这不是一元二次方程\n");
}
else
{
d=b*b-4*a*c;
if (d<0);
{
printf("该一元二次方程无实数解\n");
}
else if (d==0);
{
x=b/(-2*a);
printf("该方程有两个相等实根x=%d\n",x);
}
else
{
e=sqrt(d);
x1=(-b+e)/2*a;
x2=(-b-e)/2*a;
printf("该方程的两根分别为\n");
printf("x1=%d\n",x1);
printf("x2=%d\n",x2);
}
}
return 0;
}
Compiling...
sdy7.cpp
D:\c语言作业\sdy7.cpp(9) : warning C4390: ';' : empty controlled statement found; is this the intent?
D:\c语言作业\sdy7.cpp(12) : error C2181: illegal else without matching if
D:\c语言作业\sdy7.cpp(16) : warning C4390: ';' : empty controlled statement found; is this the intent?
D:\c语言作业\sdy7.cpp(19) : error C2181: illegal else without matching if
D:\c语言作业\sdy7.cpp(20) : warning C4390: ';' : empty controlled statement found; is this the intent?
D:\c语言作业\sdy7.cpp(24) : error C2181: illegal else without matching if
Error executing cl.exe.
sdy7.obj - 3 error(s), 3 warning(s) 展开
#include<math.h>
int main()
{
double a,b,c,d,e,x,x1,x2;
printf("请输入a,b,c");
scanf("%d,%d,%d",&a,&b,&c);
if (a==0);
{
printf("这不是一元二次方程\n");
}
else
{
d=b*b-4*a*c;
if (d<0);
{
printf("该一元二次方程无实数解\n");
}
else if (d==0);
{
x=b/(-2*a);
printf("该方程有两个相等实根x=%d\n",x);
}
else
{
e=sqrt(d);
x1=(-b+e)/2*a;
x2=(-b-e)/2*a;
printf("该方程的两根分别为\n");
printf("x1=%d\n",x1);
printf("x2=%d\n",x2);
}
}
return 0;
}
Compiling...
sdy7.cpp
D:\c语言作业\sdy7.cpp(9) : warning C4390: ';' : empty controlled statement found; is this the intent?
D:\c语言作业\sdy7.cpp(12) : error C2181: illegal else without matching if
D:\c语言作业\sdy7.cpp(16) : warning C4390: ';' : empty controlled statement found; is this the intent?
D:\c语言作业\sdy7.cpp(19) : error C2181: illegal else without matching if
D:\c语言作业\sdy7.cpp(20) : warning C4390: ';' : empty controlled statement found; is this the intent?
D:\c语言作业\sdy7.cpp(24) : error C2181: illegal else without matching if
Error executing cl.exe.
sdy7.obj - 3 error(s), 3 warning(s) 展开
2个回答
2019-03-24
展开全部
第二个else没有if吐,应该是if {} if else{} 希望能够帮助到你。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询