C语言写一个菜单,功能1为将输入数字成绩转换为等级ABC,功能二为统计不同等级的人数
时间: 2024-05-02 19:18:20 浏览: 43
简单贪吃蛇C语言代码(含菜单选等级等功能)
```
#include <stdio.h>
int main() {
int option;
int grade;
int countA = 0, countB = 0, countC = 0;
do {
printf("\n--------------------------\n");
printf("1. 将输入数字成绩转换为等级ABC\n");
printf("2. 统计不同等级的人数\n");
printf("0. 退出\n");
printf("请选择功能:");
scanf("%d", &option);
switch (option) {
case 1:
printf("请输入数字成绩:");
scanf("%d", &grade);
if (grade >= 90) {
printf("等级:A\n");
}
else if (grade >= 80) {
printf("等级:B\n");
}
else if (grade >= 70) {
printf("等级:C\n");
}
else {
printf("等级:D\n");
}
break;
case 2:
printf("A级人数:%d\n", countA);
printf("B级人数:%d\n", countB);
printf("C级人数:%d\n", countC);
break;
case 0:
printf("谢谢使用!\n");
break;
default:
printf("无效选项,请重新选择!\n");
break;
}
if (option == 1) {
if (grade >= 90) {
countA++;
}
else if (grade >= 80) {
countB++;
}
else if (grade >= 70) {
countC++;
}
}
} while (option != 0);
return 0;
}
```
阅读全文