Title【2004】


Question [2004] Grade Conversion
Problem Description
Input a grade t in a percentile system and convert it into the corresponding grade. The specific conversion rules are as follows:
90~100 is A;
80~89 is B;
70~79 is C;
60~69 is D;
0~59 is E;

 

Input
input data has multiple groups, each group occupies one line and consists of an integer.
 

Output
For each set of input data, output one line. If the input data is not in the range of 0~100, please output a line: "Score is error!".
 

Sample Input
56
67
100
123
 

Sample Output
E
D
A
Score is error!

my code:
#include<stdio.h>
intmain()
{
    int t,grade;
    while(scanf("%d",&t)!=EOF)
    {
        if(t>100||t<0)
            printf("Score is error!\n");
        grade=t/10;
        switch(grade)
        {
        case 10:
            printf("A\n");
            break;
        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:
            printf("E\n");
            break;
        }
    }

}


When I first thought about this question, I used the switch statement. There is no special reason. It was just because I saw the switch statement when I was writing the question and turning the book. I wanted to review it again, so I used it. The switch statement is not very complicated, just pay attention to its format.

At the same time, the conditions of switch conversion should be explained clearly in this C++ textbook.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325588053&siteId=291194637
Recommended