#include <stdio.h>
int main()
{
int score = 87; //考试分数为87分
switch (score)
{
case 100:
case 90:
printf("等级A");
break;
case 80:
printf("等级B");
break;
case 70:
case 60:
printf("等级C");
break;
default:
printf("等级D");
break;
}
return 0;
}
因为swith语句只能准确判断 你可以把case 80改成case 87.
或者这样改。
#include <stdio.h>
int main()
{
int score = 87/10; //考试分数为87分
switch (score)
{
case 10:
case 9:
printf("等级A");
break;
case 8:
printf("等级B");
break;
case 7:
case 6:
printf("等级C");
break;
default:
printf("等级D");
break;
}
return 0;