求 用C语言中switch语句编写学生成绩问题

2024-11-27 10:33:23
推荐回答(3个)
回答1:

#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;
  }
  }

回答2:

……scanf("%f",&a);b=(int)(a/10);switch(b){ case 9: printf("A");break; ……}主梁凳要橡誉旅是case后面要常量表达式,这样虚改就必须把区间转化为单值!

回答3:

switch(score/10){case 9 :putchar('A');}