Compute a student's average score across three tests using integer division so the result is a whole number.
You start with:
// Rust: the editor starts empty - declare the data yourself, for example:
let test1: i32 = 85;
let test2: i32 = 92;
let test3: i32 = 78;
Build:
Average: 85
Rules:
- Compute the integer average of
test1,test2, andtest3using integer division (i32divided byi32already drops the remainder). - Print
"Average: "followed by the average, for exampleprintln!("Average: {}", average);
Rust
i32 / i32 truncates, so (test1 + test2 + test3) / 3 already gives an integer.
let test1: i32 = 85;
let test2: i32 = 92;
let test3: i32 = 78;
let average: i32 = (test1 + test2 + test3) / 3;
println!("Average: {}", average);
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
