fork download
  1. #include <stdio.h>
  2.  
  3. // Function prototype
  4. char getGrade(int score);
  5.  
  6. // Function definition
  7. /**
  8.  * Function Name: getGrade
  9.  *
  10.  * Function Block:
  11.  * Determines the letter grade based on the given score.
  12.  *
  13.  * @param score The test score (0-100).
  14.  * @return The letter grade corresponding to the score, or 'I' for invalid scores.
  15.  */
  16. char getGrade(int score) {
  17. if (score < 0 || score > 100) {
  18. return 'I'; // Invalid score
  19. } else if (score >= 90) {
  20. return 'A';
  21. } else if (score >= 80) {
  22. return 'B';
  23. } else if (score >= 70) {
  24. return 'C';
  25. } else if (score >= 60) {
  26. return 'D';
  27. } else {
  28. return 'F';
  29. }
  30. }
  31.  
  32. int main() {
  33. int score;
  34.  
  35. // Test cases
  36. score = 95;
  37. printf("Score: %d, Grade: %c\n", score, getGrade(score)); // Expected output: A
  38.  
  39. score = 85;
  40. printf("Score: %d, Grade: %c\n", score, getGrade(score)); // Expected output: B
  41.  
  42. score = 75;
  43. printf("Score: %d, Grade: %c\n", score, getGrade(score)); // Expected output: C
  44.  
  45. score = 65;
  46. printf("Score: %d, Grade: %c\n", score, getGrade(score)); // Expected output: D
  47.  
  48. score = 55;
  49. printf("Score: %d, Grade: %c\n", score, getGrade(score)); // Expected output: F
  50.  
  51. score = -5;
  52. printf("Score: %d, Grade: %c\n", score, getGrade(score)); // Expected output: I
  53.  
  54. score = 105;
  55. printf("Score: %d, Grade: %c\n", score, getGrade(score)); // Expected output: I
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Score: 95, Grade: A
Score: 85, Grade: B
Score: 75, Grade: C
Score: 65, Grade: D
Score: 55, Grade: F
Score: -5, Grade: I
Score: 105, Grade: I