Easy 0 solved 0% acceptance

Letter Grade

Turn a test score into a letter grade.

What you'll learn

  • Map score ranges to grades
  • Order conditions from highest to lowest
  • Handle boundary values exactly

Problem

Convert a score from 0 to 100 into a letter grade: 90 and above is A, 80–89 is B, 70–79 is C, 60–69 is D, and below 60 is F.

Implement letter_grade(score).

Input

score: The test score.

Output

Return the letter as a one-character string.

Constraints

0 ≤ score ≤ 100

Examples

Example 1
Input:
score = 85

Expected output:
expected = "B"
Input:
long long score = 85;

Expected output:
std::string expected = "B";
Input:
long score = 85;

Expected output:
string expected = "B";

Explanation

85 is at least 80 but below 90, so the grade is B.

Example 2
Input:
score = 59

Expected output:
expected = "F"
Input:
long long score = 59;

Expected output:
std::string expected = "F";
Input:
long score = 59;

Expected output:
string expected = "F";

Explanation

59 is below 60, so the grade is F.

How to approach it

Try on your own first, then open one hint at a time.

Hint 1

Compare the score against the highest passing threshold first and work downward.

Hint 2

A chain of ordered comparisons is the simplest way to map ranges to letters.

Hint 3

Make sure boundary scores like 90, 80, 70, and 60 fall into the higher grade band.

Expected complexity

O(1) time, O(1) extra space

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.