C语言实现判断分数等级

从屏幕上输入一个学生的成绩(0-100),对学生成绩进行评定:

  <=60为"E"

       60~69为"D"

       70~79为"C"

       80~89为"B"

       90以上为"A"

       <0或>100提示成绩输入出错

 

实现代码:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6     int socre;
 7     printf("plz input a score:");
 8     scanf("%d",&socre);
 9     //printf("socre:%d",socre);
10     if (socre > 100 || socre < 0)
11     {
12         printf("plz input socre between 0 and 100");
13         return -1;
14     }
15     socre /= 10;
16     switch(socre)
17     {
18     case 9:
19     case 10:
20         printf("A");
21         break;
22     case 8:
23         printf("B");
24         break;
25 
26     case 7:
27          printf("C");
28          break;
29     case 6:
30        printf("D");
31        break;
32      default:
33         printf("E");
34     }
35     return 0;
36 }

没有解决的问题,在输入字母等字符时,并没有报错,有待进一步优化!

使用的环境未qt!

posted on 2018-08-04 18:05  skyfall007  阅读(5903)  评论(0编辑  收藏  举报

导航