(2) 给出一个百分制成绩,要求输出成绩等级Excellent,Good,Middle,Passed,Failed。其中,90分以上为E
void main()
{
float score;
char grade;
printf("请输入学生成绩:\n");
scanf("%f,&score");
while(score>100||score<0)
{
printf("Illegal\n");
}
switch((int)(score/10))
{
case 10:
case 9:printf("grade='Excellent'\n");break;
case 8:printf("grade='Good'\n");break;
case 7:printf("grade='Middle'\n");break;
case 6:printf("grade='Passed'\n");break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:printf("grade='failed'\n");
}
printf("成绩是%5.2f,等级是%s\n",score,grade);
} 展开
#include<stdio.h>
void main()
{
float score;
char *grade[12];
printf("请输入学生成绩:\n");
scanf("%f",&score);
while(score>100||score<0)
{
printf("Illegal\n");
}
switch((int)(score/10))
{
case 10:
case 9:
*grade="Excellent";
break;
case 8:
*grade="Good";
break;
case 7:
*grade="Middle";
break;
case 6:
*grade="Passed";
break;
default:
*grade="failed";
break;
}
printf("成绩是%5f,等级是%s\n",score,*grade);
}
问题有点多,我手拙改了改··
希望采纳~
scanf("%f,&score");这里引号写错了。。scanf("%f",&score);
还有grade其实没有给值。最后输不出grade等级
#include<stdio.h>
void main()
{
float score;
printf("请输入学生成绩:\n");
scanf("%f",&score);
if(score>100||score<0)
{
printf("Illegal\n");
return;
}
switch((int)(score/10))
{
case 10:printf("成绩是%g,grade='Excellent'\n",score);break;
case 9:printf("成绩是%g,grade='Excellent'\n",score);break;
case 8:printf("成绩是%g,grade='Good'\n",score);break;
case 7:printf("成绩是%g,grade='Middle'\n",score);break;
case 6:printf("成绩是%g,grade='Passed'\n",score);break;
default:printf("成绩是%g,grade='failed'\n",score);break;
}
}
#include <stdio.h>
#include <string.h>
void main()
{
float score;
char grade[20];
printf("请输入学生成绩:\n");
scanf("%f",&score);
if((0<=score)&&(score<=100))
{
switch((int)(score/10))
{
case 10:
case 9:strcpy(grade,"Excellent");break;
case 8:strcpy(grade,"Good");break;
case 7:strcpy(grade,"Middle");break;
case 6:strcpy(grade,"Passed");break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:strcpy(grade,"failed");break;
}
printf("成绩:%5.2f\n等级:%s\n",score,grade);
}
else
{
printf("输入错误!\n");
}
}