basics · beginner · ~15 min

Letter grade

Map ranges to discrete outputs.

Challenge

Convert a numeric score into a letter grade by checking ordered thresholds.

Task

Implement char grade_letter(int score) that maps a score to a letter: 'A' for score >= 90, 'B' for >= 80, 'C' for >= 70, 'D' for >= 60, and 'F' otherwise. Check the highest threshold first so each band wins correctly. No main — the grader calls it.

Input

A single int score (typically 0-100).

Output

Returns the grade letter: one of 'A', 'B', 'C', 'D', 'F'.

Example

grade_letter(95)   ->   'A'
grade_letter(82)   ->   'B'
grade_letter(71)   ->   'C'
grade_letter(60)   ->   'D'
grade_letter(40)   ->   'F'

Edge cases

  • A score of exactly 60 is a 'D'; below 60 is 'F'.

Rules

  • Test thresholds from highest to lowest.

Input format

A single int score (typically 0-100).

Output format

The grade letter: 'A', 'B', 'C', 'D', or 'F'.

Constraints

Thresholds: >=90 A, >=80 B, >=70 C, >=60 D, else F.

Starter code

char grade_letter(int score) {
    /* TODO */
    return 'F';
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.