re: Daily Challenge #68 - Grade Book VIEW POST

FULL DISCUSSION
 

Rust:

fn grade(a: u32, b: u32, c: u32) -> String {
    let mean = (a + b + c) / 3;
    let letter = match dbg!(mean) {
        _ if (90..=100).contains(&mean) => "A",
        _ if (80..90).contains(&mean) => "B",
        _ if (70..80).contains(&mean) => "C",
        _ if (60..70).contains(&mean) => "D",
        _ if (0..60).contains(&mean) => "F",
        _ => unreachable!("mean ({}) can't be < 0", mean),
    };
    let sign = if mean % 10 < 5 { "-" } else { "+" };
    format!("{}{}", letter, sign)
}
code of conduct - report abuse