标签:使用 os io 数据 art ar div amp
#include <iostream>
using namespace std;
int main()
{
int a;
cout<<"please input your score: "<<endl;
cin>>a;
if(a>100||a<0)
cout<<"wrong input! please try again!"<<endl;
else if(a>=90&&a<=100)
cout<<"you get an A! you are doing great job!"<<endl;
else if(a>=80&&a<90)
cout<<"you get a B! keep going!"<<endl;
else if(a>=70&&a<80)
cout<<"you get a C! It‘s OK,you can do better!"<<endl;
else if(a>=60&&a<70)
cout<<"you get an E! you pass the exam."<<endl;
else if(a<60)
cout<<"you did‘not pass the exam,but don‘t lose heart."<<endl;
return 0;
}
(2)采用switch语句:
#include <iostream>
using namespace std;
int main()
{
int score,temp;//先定义,后使用
char grade;//注意定义等级时须定义为字符型
cout<<"please input your score: "<<endl;
cin>>score;
temp=(int)score/10;//强制类型转换
switch(temp)//输入之前的数据
{
case 10:grade=‘A+‘;break;
case 9:grade=‘A‘;break;
case 8:grade=‘B‘;break;
case 7:grade=‘C‘;break;
case 6:grade=‘D‘;break;
default :grade=‘E‘;break;//其他默认结果输出,冒号不能忘
}
cout<<"you grade is: "<<grade<<endl;
return 0;
}
3.百分制成绩转换为5个等级输出,布布扣,bubuko.com
3.百分制成绩转换为5个等级输出
标签:使用 os io 数据 art ar div amp
原文地址:http://www.cnblogs.com/jixiaowu/p/3890240.html