百分制转换为五分制的算法


/*编写一个将百分制转换为五分制的算法(使用if-else语句),
要求平均比较次数尽可能少.假设学生成绩分布如下:
等级      A      B      C      D      E
分数   90~100  80~89  70~79  60~69   0~59
百分比  0.18    0.23   0.31   0.15   0.13
*/

#include<iostream>
using namespace std;
//分类与判定
char trans(float x)
{
	if(x>=80)
		if(x>=90)  return 'A';
		else	   return 'B';
	else if(x>70)  return 'C';
	else if(x>60)  return 'D';
	else	return 'E';
}

int main()
{
	float score;
	int i=0;
	do
	{
		cout<<"请输入你的百分制成绩:";
		cin>>score;
		i++;
		cout<<"恭喜你!!!您的五分制等级是:";
		cout<<trans(score);
		cout<<endl;
	}while(i<=10);
	
	system("pause");
	return 0;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM