#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加上{}
希望对题主有所帮助,可以的话,帮忙点个采纳!
#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 if,后面加了封号,把他去掉
else if(t>25&&t<27)