猿问

为什么输入任何数字的时候都是输出A,该如何改?

#include<stdio.h>
int main()
{
float x;
int leap;
scanf("%f",&x);
if(x>=90)
{
if(x>=80&&x<90)
{
if(x>=70&&x<80)
{
if(x>=60&&x<70)
{
if(x<60)
leap=1;
}else leap=2;
}else leap=3;
}else leap=4;
}else leap=5;
switch(leap)
{case 1:printf("you grade is:E");break;
case 2:printf("you grade is:D");break;
case 3:printf("you grade is:C");break;
case 4:printf("you grade is:B");break;
case 5:printf("you grade is:A");break;
}
return 0;

}

凤凰求蛊
浏览 194回答 2
2回答

倚天杖

前面if嵌套不对。修改如下#include<stdio.h>int main(){float x;int leap;scanf("%f",&x);if(x<90){if(x<80){if(x<70){if(x<60){leap=1;}else leap=2;}else leap=3;}else leap=4;}else leap=5;switch(leap){case 1:printf("you grade is:E");break;case 2:printf("you grade is:D");break;case 3:printf("you grade is:C");break;case 4:printf("you grade is:B");break;case 5:printf("you grade is:A");break;}return 0;}

qq_遁去的一_1

if(x>=90){if(x>=80&&x<90){if(x>=70&&x<80){if(x>=60&&x<70){if(x<60)leap=1;}else leap=2;}else leap=3;}else leap=4;}else leap=5;这里有逻辑错误!
随时随地看视频慕课网APP
我要回答