错误提示 error C2181: illegal else without matching if,而且是最后一个else处错误,求高手解答

#include<stdio.h>
#include<math.h>
void main()
{
double a,b,c,x1,x2,dise;
dise=b*b-4*a*c;
printf("input a b c:");
scanf("%f,%f,%f",&a,&b,&c);
if(a=0)
printf("该方程不是二元方程");
else
if(dise=0)
printf("有两个相等的实根");
else
if(dise>0)
x1=(-b+sqrt(dise))/2*a;
x2=(-b+sqrt(dise))/2*a;
printf("有两个不相等的实根,%f,%f",x1,x2);
else
if(dise<0)
printf("没有实根");
}

第1个回答  2019-07-08
首先条件里面if(a==0),不是a=0,包括下面的dise,这是一个错误。
第二个错误是当条件语句下面有多条执行的语句需要用{}把这些语句包含进去。
第2个回答  2019-07-08
#include<math.h>
int main()
{
double a, b, c, x1, x2, dise;
printf("input a b c:");
scanf("%lf%lf%lf", &a, &b, &c);
if (a == 0)
printf("该方程不是一元二次方程");
else
{
dise = b * b - 4 * a * c;
if (dise == 0)
printf("有两个相等的实根: %lf", -b / (2 * a));
else if (dise > 0)
{
x1 = (-b + sqrt(dise)) / (2 * a);
x2 = (-b - sqrt(dise)) / (2 * a);
printf("有两个不相等的实根: %lf, %lf", x1, x2);
}
else
printf("没有实根");
}
return 0;
}本回答被网友采纳
第3个回答  2019-07-08
emmm……你倒数第二个if后面的几个语句(到下一个else之前)应该用{}括起来。追答

if里判断的表达式也是个问题,要用两个=,但这个应该不会报错

相似回答