题解 | #判断成绩等级#
判断成绩等级
https://www.nowcoder.com/practice/1a12e246764243ada9043699b9a1e7ef
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if(x>-1&&x<101){ if(x<60){ cout<<"差"; }else if(x<70){ cout<<"及格"; }else if(x<80){ cout<<"中"; }else if(x<90){ cout<<"良"; }else{ cout<<"优秀"; } }else{ cout<<"成绩不合法"; } return 0; }
用双重if先判断合不合法,再判断等级。