Combine variables and arithmetic to compute a student's weighted final score.
Weights: Homework 20%, Midterm 30%, Final 50%. Each weighted part is rounded down to a whole number before the parts are added.
You start with:
// Rust: the editor starts empty - declare the data yourself, for example:
let homework = 90;
let midterm = 82;
let finalExam = 88;
Build:
Score: 86
Rules:
- Compute
score = homework * 20 / 100 + midterm * 30 / 100 + finalExam * 50 / 100. - Each part is rounded down because
i32divided byi32drops the remainder (the third variable is namedfinalExam). - For the starting data: 18 + 24 + 44 = 86.
- Print
"Score: "followed by the score, for exampleprintln!("Score: {}", score);
The third variable is named
finalExam. i32 / i32 truncates, so each weight already rounds down.
let homework = 90;
let midterm = 82;
let finalExam = 88;
let score = homework * 20 / 100 + midterm * 30 / 100 + finalExam * 50 / 100;
println!("Score: {}", score);
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
