rust 1.17.0
use std::io;
fn main() {
println!("\n\tEnter your score: ");
//read user input
let mut input= String::new(); io::stdin()
.read_line(&mut input)
.expect("failed to read input.");
//convert input to integer
let score: i32 = input.trim().parse().expect("invalid input");
let s= calc(score);
print!("\n\tYour grade: {}",s);
return ;
}
fn calc(sco: i32) -> &'static str{
let mut gra= "F";
match sco {
90...100 => { gra= "A"; }
80...89 => { gra= "B"; }
70...79 => { gra= "C"; }
60...69 => { gra= "D"; }
_ => { println!("\n\tERROR: Invalid score\n"); }
}
gra
}
Comments