fork download
  1. #include <stdio.h>
  2.  
  3. char calcLetterGrade(int score);
  4.  
  5. int main(void)
  6. {
  7. int score = 85;
  8. char LetterGrade = calcLetterGrade(score);
  9. printf("%c\n", LetterGrade);
  10.  
  11. return 0;
  12. }
  13.  
  14. char calcLetterGrade(int score) // Corrected function definition
  15. {
  16. char result; //* letter grade result */
  17.  
  18.  
  19. if (score > 100 || score < 0) // check for invalid score
  20. return 'I';
  21.  
  22. // Map score to letter grade
  23. if (score >= 90 && score <= 100) // 90-100 is an A
  24. result = 'A';
  25. else if (score >= 80 && score <= 89) // 80-89 is a B
  26. result = 'B';
  27. else if (score >= 70 && score <= 79) // 70-79 is a C
  28. result = 'C';
  29. else if (score >= 61 && score <= 69) // 61-69 is a D
  30. result = 'D';
  31. else
  32. result = 'F'; // any other results passed through are fails as invalids were caught
  33.  
  34. return result;
  35. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
B