C/C++ Programming Learning-Week 10⑨ Grade Conversion

Topic link

Title description

Enter a percentile score t and convert it to 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;

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

Output
For each set of input data, output one row. 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!

Ideas

According to the input score and corresponding rules, it is converted to the corresponding level. If the input data is not in the range of 0-100, a line of output: "Score is error!" .

C++ code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int a;
	while(cin >> a)
	{
    
    
		if(a <= 59 && a >= 0) cout << "E" << endl;
		else if(a <= 69 && a >= 60) cout << "D" << endl;
		else if(a <= 79 && a >= 70) cout << "C" << endl;
		else if(a <= 89 && a >= 80) cout << "B" << endl;
		else if(a <= 100 && a >= 90) cout << "A" << endl;
		else cout << "Score is error!" << endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113099791