题目:
如果学校实行奖学金制度,规定学生根据期末考试成绩可以获得一定奖励,按全部功课平均分数(100分制)计算,规定60分以下不奖励,60分以上同学超出60分多出来的分数可以奖励,60分(含)~70分(不含)部分每一分奖励10.9元;70分(含)~80(不含)部分每一分奖励20.9元;80分(含)~90分(不含)部分每一分奖励30.9元,90分(含)~100分(含)部分每一分奖励40.9元
请编写一个程序,当你从键盘输入某个同学的分数(含小数),马上输出这个同学赢得的奖学金金额。
#include
int main()
{
float score, reward;
while (1) {
printf("Please enter the student's score: \n");
scanf("%f", &score);
if (score >= 0 && score <= 100) break;
}
reward = 0;
if (score >= 90){
reward = (score - 89) * 40.9 + 309 + 209 + 109;
} else if (score >= 80) {
reward = (score - 79) * 30.9 + 209 + 109;
} else if (score >= 70) {
reward = (score - 69) * 20.9 + 109;
} else if (score >= 60) {
reward = (score - 59) * 10.9;
}
printf("The amount of scholarship the student won: %.2f", reward);
}
这里应该是用switch函数
先用if语句将60分以上和60分以下分开,将60分以上的分数除以10,得到十分位的数字
再用case检测并逐个计算输出
#include
int main()
{ float x,y=0;
scanf("%f",&x);
if(x>100)
{ printf("Error");
return 0;
}
if(x>=90)
{ y=40.9*(x-90);
x=90;
}
if(x>=80)
{ y+=30.9*(x-80);
x=80;
}
if(x>=70)
{ y+=20.9*(x-70);
x=70;
}
if(x>=60)y+=10.9*(x-60);
printf("%.2f\n",y);
return 0;
}