Start learning free

LESSON 179 OF 414 · PROJECTS: EVERYDAY PROGRAMS

Report Card V3 - Letter Grade in Rust

Practice

Use if/else if/else to turn a numeric score into a letter grade.

You start with:

// Rust: the editor starts empty - declare the data yourself, for example:
let score = 85;

Build:

Grade: B

Rules:

  • score >= 90 is "A"; 80-89 is "B"; 70-79 is "C"; 60-69 is "D"; below 60 is "F".
  • The boundaries count: a score of exactly 90 is an A, exactly 80 a B, exactly 70 a C, exactly 60 a D, and 59 is an F.
  • Print "Grade: " followed by the letter grade, for example println!("Grade: {}", grade);

Declare let mut grade = ""; first, then assign in an if/else if chain.

let score = 85;
let mut grade = "";
if score >= 90 {
    grade = "A";
} else if score >= 80 {
    grade = "B";
} else if score >= 70 {
    grade = "C";
} else if score >= 60 {
    grade = "D";
} else {
    grade = "F";
}
println!("Grade: {}", grade);

STEP 1 OF 8
    Ctrl + Enter to check

    Report Card V3 in Rust

    Keep going with RustAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free