c语言程序报错else without a previous if

#include <stdio.h>
#include <stdlib.h>

int main()
{
float h,w;
printf ("Please enter h,w:\n",h,w);
scanf("%f,%f",&h,&w);
float t;
t =w/(h*h);
if (t<18)
{
printf("t=%f\tLower weight!\n",t);
}
else if(t>=18&&t<=25)
{
printf("t=%f\tStandard weight!\n",t);
}
else if(t>25&&t<27);
{
printf("t=%f\tHigher weight!\n",t);
}
else
printf("t=%f\tToo fat!\n",t);
return 0;
}

报错:else without a previous if

给else加上{}

img


;去掉

img

希望对题主有所帮助,可以的话,帮忙点个采纳!


#include <stdio.h>
#include <stdlib.h>

int main()
{
    float h, w;
    printf("Please enter h,w:\n", h, w);
    scanf("%f,%f", &h, &w);
    float t;
    t = w / (h*h);
    if (t < 18)
    {
        printf("t=%f\tLower weight!\n", t);
    }
    else if (t >= 18 && t <= 25)
    {
        printf("t=%f\tStandard weight!\n", t);
    }
    else if (t > 25 && t < 27)
    {
        printf("t=%f\tHigher weight!\n", t);
    }
    else
    {
        printf("t=%f\tToo fat!\n", t);
    }
    return 0;
}

img


这里不需要分号,这里是条件判断,不是语句。希望采纳

你是倒数第二个else if,后面加了封号,把他去掉
else if(t>25&&t<27)