法一:
#include<iostream>
using namespace std;
int main()
{
int score;
cout << "请输入学生分数:" << endl;
cin >> score;
if (score >= 90 && score <= 100)
{
cout << "优秀" << endl;
}
else if (score >= 80 && score <= 89)
{
cout << "良好" << endl;
}
else if (score >= 80 && score <= 89)
{
cout << "良好" << endl;
}
else if (score >= 70 && score <= 79)
{
cout << "中等" << endl;
}
else if (score >= 60 && score <= 69)
{
cout << "及格" << endl;
}
else
{
cout << "不及格" << endl;
}
return 0;
}
法2:
#include<iostream>
using namespace std;
int main()
{
int score;
cout << "请输入学生分数:" << endl;
cin >> score;
switch (score / 10)
{
case 10:
case 9:
cout << "优秀" << endl;
break;
case 8:
cout << "良好" << endl;
break;
case 7:
cout << "中等" << endl;
break;
case 6:
cout << "及格" << endl;
break;
default:
cout << "不及格" << endl;
break;
}
return 0;
}