#include
void main()
{
double score;
printf("请输入分数:\n");
scanf("%lf",&score);
switch((int)(score/10))//switch((int)score/10)出现严重错误,switch(((int)score)/10)出现严重错误,
{
case 10:
case 9:printf("A(最好)\n");break;
case 8:printf("B(优秀)\n");break;
case 7:printf("C(良好)\n");break;
case 6:printf("D(及格)\n");break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:printf("E(不及格)\n"信洞);break;
default:printf("Error!\n");
}
}
例二:
#include
void main()
{
char rank;
printf("请输入分数等级:(A、B、C、D、E)\n");
scanf("%c",&rank);
switch(rank)//switch((int)score/10)出现严重错误,switch(((int)score)/10)出现严重错误,
{
case 'A':printf("A(90~100)\n");break;
case 'B':printf("B(80~89)\n");break;
case 'C':printf("C(70~79)\n");break;
case 'D':printf("D(60~69)\n");break;
case 'E':printf("E(0~59)\n");break;
滑巧枯 default:printf("error!\n");break;
}
}
……scanf("%f",&a);b=(int)(a/10);switch(b){ case 9: printf("A");break; ……}主梁凳要橡誉旅是case后面要常量表达式,这样虚改就必须把区间转化为单值!
switch(score/10){case 9 :putchar('A');}