主题:简单的程序优化
将百分制的成绩按等级输出,下面是一种实现方法,各位大侠有没有更有效的算法?
#include<iostream>
using namespace std;
void main()
{
int n;
cout<<"Enter a score:";
cin>>n;
switch(n/10)
{
case 10: case 9:
cout<<"The degree is A"<<endl;
break;
case 8:
cout<<"The degree is B"<<endl;
case 7: case 6:
cout<<"The degree is C"<<endl;
Default:
cout<<"The degree id D"<<endl;
}
}
谢谢了····
#include<iostream>
using namespace std;
void main()
{
int n;
cout<<"Enter a score:";
cin>>n;
switch(n/10)
{
case 10: case 9:
cout<<"The degree is A"<<endl;
break;
case 8:
cout<<"The degree is B"<<endl;
case 7: case 6:
cout<<"The degree is C"<<endl;
Default:
cout<<"The degree id D"<<endl;
}
}
谢谢了····