注册 登录
编程论坛 C语言论坛

c语言出现illegal else without matching if 执行 cl.exe 时出错.

c语言新手啊 发布于 2019-10-15 23:22, 2611 次点击
#include<stdio.h>
#include<math.h>
int main()
{
 double a,x,y;
 scanf("%lf",&x);
 a=10.2;
 if(x>=-100,'&&',x<=0);
 {
  y=sqrt(a*a+x*x);
  printf("%lf",y);
  else if(x>=0)
     y=3*a*x*x+4*a*x-1;
    printf("%lf",y);
 };
return 0;
 };
3 回复
#2
bcbbcclbbc2019-10-16 06:11
分号为一个语句的结束,你if语句后直接接了一个分号(空语句)而且后面还有语句,后面的else找不到与之对应的if就会报错。
大括号括起来的语句称为复合语句,后面可以不用加分号
#3
rjsp2019-10-16 08:30
代码要排版,别团得像坨屎

程序代码:
#include <stdio.h>
#include <math.h>

int main( void )
{
    double x;
    scanf( "%lf", &x );

    double y = 0;
    const double a = 10.2;
    if( x>=-100 && x<=0 )
    {
        y = sqrt(a*a+x*x); // 最好用 y = hypotf(a,x);
    }
    else if( x>=0 )
    {
        y = 3*a*x*x + 4*a*x - 1;
    };
    printf( "%lf\n", y );

    return 0;
}

#4
c语言新手啊2019-10-16 12:15
回复 3楼 rjsp
好的,谢谢
1