fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main() {
  5. int i;
  6. float point, co_curricular, academic_merit, total_merit;
  7. float total_points = 0.0;
  8. char grade;
  9.  
  10. // 显示评分表
  11. printf("---------------------------------------\n");
  12. printf("| Grade | A | B | C | D | E |\n");
  13. printf("---------------------------------------\n");
  14. printf("| Points| 4 | 3 | 2 | 1 | 0 |\n");
  15. printf("---------------------------------------\n");
  16.  
  17. // 输入四科成绩
  18. for (i = 1; i <= 4; i++) {
  19. printf("%d. Enter grade of the subject\t: ", i);
  20. scanf(" %c", &grade); // 跳过空白字符
  21. grade = toupper(grade); // 转大写
  22.  
  23. switch (grade) {
  24. case 'A': point = 4.00; break;
  25. case 'B': point = 3.00; break;
  26. case 'C': point = 2.00; break;
  27. case 'D': point = 1.00; break;
  28. case 'E': point = 0.00; break;
  29. default:
  30. printf("Invalid grade entered.\n");
  31. return 1; // 错误终止
  32. }
  33.  
  34. printf("Points obtain\t\t\t: %.2f\n", point);
  35. total_points += point;
  36. }
  37.  
  38. // 输入并验证课外活动分
  39. printf("\nEnter the co-curricular merit\n");
  40. printf("Co-curricular merit\t\t: ");
  41. scanf("%f", &co_curricular);
  42.  
  43. if (co_curricular < 0 || co_curricular > 10) {
  44. printf("Error: Co-curricular merit must be 0-10.\n");
  45. return 1;
  46. }
  47.  
  48. // 计算与输出
  49. academic_merit = total_points / 4;
  50. total_merit = (academic_merit * 90) / 4 + co_curricular;
  51.  
  52. printf("\nAcademic merit\t\t\t: %.2f\n", academic_merit);
  53. printf("Total merit points\t\t: %.2f\n", total_merit);
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0s 5284KB
stdin
a
a
a
e

7
stdout
---------------------------------------
| Grade | A | B | C | D | E |
---------------------------------------
| Points| 4 | 3 | 2 | 1 | 0 |
---------------------------------------
1. Enter grade of the subject	: Points obtain			: 4.00
2. Enter grade of the subject	: Points obtain			: 4.00
3. Enter grade of the subject	: Points obtain			: 4.00
4. Enter grade of the subject	: Points obtain			: 0.00

Enter the co-curricular merit
Co-curricular merit		: 
Academic merit			: 3.00
Total merit points		: 74.50