#include
int main()
{
int score=90;
char grand;
if(score>=60)grand='C';
if(score>=70)grand='B';
if(score>=80)grand='A';
else if(score>=90)grand='a';
else grand='*';
printf("%c\n",grand);
return 0;
}
这一行满足就直接不走后边else if 跟else
if(score>=80)grand='A';这个写法,90也是在里面了
应该改成 if(score>=80 && score<90)grand='A';
大于等于80后,你应该在里面判断是否大于90,而不是else if
你应该把>=90最先判断
然后后面的else if
else if ,else 应该是与最近的if匹配,也就是if(score>=80),其他if就是按顺序执行下来
但是if ,else if 与else只是顺序看下来之后,如果一旦满足其中一个条件 执行之后区域就不执行。
所以,本题,会执行所有的if,然后grand不断被更新,一直到最后一个if满足条件后,后面的else if还有else就不会执行了。但是如果最后的if不满足,就会再往下看else if与else。
(希望对你有帮助,有问题也可以私信或者直接评论哦)