关于C语言多分支选择结构switch case,急!例题如下,请问我哪里做错了呀?·
EG:从键盘上输入一个百分制成绩score,按下列原则输出其等级:score≥90,等级为A;80≤score<90,等级为B;70≤score<80,等级为C;60≤s...
EG:从键盘上输入一个百分制成绩score,按下列原则输出其等级:score≥90,等级为A;80≤score<90,等级为B;70≤score<80,等级为C;60≤score<70,等级为D;score<60,等级为E。
main(){ int score; char grade; printf("input a score(0~100)\n"); scanf("%d",&score);
switch (score/10) { case 0:printf("grade=E\n");break; case 1: case 2: case 3: case 4: case 5: case 6:printf("grade=D\n");break; case 7:printf("grade=C\n");break; case 8:printf("grade=B\n");break; case 9:printf("grade=A\n");break; case 10: default: printf("The score is out of range!\n"); } getch();} 展开
main(){ int score; char grade; printf("input a score(0~100)\n"); scanf("%d",&score);
switch (score/10) { case 0:printf("grade=E\n");break; case 1: case 2: case 3: case 4: case 5: case 6:printf("grade=D\n");break; case 7:printf("grade=C\n");break; case 8:printf("grade=B\n");break; case 9:printf("grade=A\n");break; case 10: default: printf("The score is out of range!\n"); } getch();} 展开
1个回答
2013-12-19
展开全部
void mian(){
int score;
char grade;
printf("input a score(0~100)\n");
scanf("%d",&score);
switch (score/10) {
case 0:case 1:case 2:case 3:case 4: case 5:
printf("grade=E\n");break;
case 6:
printf("grade=D\n");break;
case 7:
printf("grade=C\n");break;
case 8:
printf("grade=B\n");break;
case 9:
printf("grade=A\n");break;
default:
printf("The score is out of range!\n");
}
}
int score;
char grade;
printf("input a score(0~100)\n");
scanf("%d",&score);
switch (score/10) {
case 0:case 1:case 2:case 3:case 4: case 5:
printf("grade=E\n");break;
case 6:
printf("grade=D\n");break;
case 7:
printf("grade=C\n");break;
case 8:
printf("grade=B\n");break;
case 9:
printf("grade=A\n");break;
default:
printf("The score is out of range!\n");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询