fork download
  1. #include <stdio.h>
  2.  
  3. char calculateGrade(int score)
  4. {
  5. // Score thresholds for each grade
  6. if (score < 0 || score > 100)
  7. {
  8. return ('I');
  9. }
  10.  
  11. else if (score >= 90 && score <= 100)
  12. {
  13. return ('A');
  14. }
  15.  
  16. else if (score >= 80 && score <= 89)
  17. {
  18. return ('B');
  19. }
  20.  
  21. else if (score >= 70 && score <= 79)
  22. {
  23. return ('C');
  24. }
  25.  
  26. else if (score >= 60 && score <= 69)
  27. {
  28. return ('D');
  29. }
  30.  
  31. else
  32. {
  33. return ('F');
  34. }
  35. }
  36.  
  37. int main() {
  38. int score;
  39. printf("Enter the test score: ");
  40. scanf("%d", &score);
  41.  
  42. char grade = calculateGrade(score);
  43. if (grade == 'I') {
  44. printf("Invalid score!\n");
  45. } else {
  46. printf("Grade: %c\n", grade);
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5308KB
stdin
89
stdout
Enter the test score: Grade: B