#include
using namespace std;
void main(){
cout<<"请输入成绩";
int score;
cin>>score;
while(score<0||score>100){
cout<<"您输入的成绩不符合要求,请重新输入";
cin>>score;
}
switch(score/10){
case 10:
case 9:
cout<<"A";
break;
case 8:
cout<<"B";
break;
case 7:
cout<<"C";
break;
case 6:
cout<<"D";
break;
default:
cout<<"E";
}
system("pause");
}
这种情况是标准的使用switch的情况,用if也行,更简单:
#include
using namespace std;
void main(){
cout<<"请输入成绩";
int score;
cin>>score;
while(score<0||score>100){
cout<<"您输入的成绩不符合要求,请重新输入";
cin>>score;
}
if(score>=90){
cout<<"A";
}else{
if(score>=80){
cout<<"B";
}else{
if(score>=70){
cout<<"C";
}else{
if(score>=60){
cout<<"D";
}else{
cout<<"E";
}
}
}
}
system("pause");
}