题目4:统计学生成绩:输入一个正整数 n ,再输入 n 个学生的成绩,统计五分制成绩的分布。百分制成绩到五分制成绩的转换规则:大于或等于 90 分为 A ,小于 90 分且大于或等于 80 分为 B,小于 80 分且大于或等于 70 为 C,小于 70 分且大于或等于 60 为D,小于 60 分为E。试编写相应程序。
我写的:
#include<stdio.h>
int main()
{
int n, i; //学生人数,以及循环当中的i
double score; //分数
printf("please input the numbers of your students:\n"); //提示输入学生人数n
scanf_s("%d", &n); //读取输入值
printf("please input the score of your students:\n"); //提示输入分数score
for (i = 1; i <= n; i++)
{
scanf_s("%lf", &score);
if (score >= 90)
{
printf("%lf:A\n", score); //分数大于90,评级为A(之后的也类似)
}
else if (score < 90 && score >= 80)
{
printf("%lf:B\n", score);
}
else if (score < 80 && score >= 70)
{
printf("%lf:C\n", score);
}
else if ("score<70&&score>=60")
{
printf("%lf:D\n", score);
}
else if("score<60")
{
printf("%lf:E\n", score); //分数小于60,评级为E(这里出现错误)
}
}
return 0;
}
调试结果:
图片好像不行,文字输入调试结果如下:
please input the numbers of your students:
1
please input the score of your students:
43
43.000000:D
我的本意是想把分数低于六十分的评级为E 但是不知道为什么一直就是D,求解(勿喷)
编译器:visual studio 2022 题目来源:c语言程序设计第四版,何钦铭,颜晖主编
第三章习题三程序设计题第四题