Commit b687c6b5 authored by Christoph Häfner's avatar Christoph Häfner

Add calculate-bmi

parent 971c02a6
fn bmi(weight: u32, height: f32) -> &'static str {
return match weight as f32 / height.powi(2) {
_ if bmi <= 18.5 => "Underweight",
_ if bmi <= 25.0 => "Normal",
_ if bmi <= 30.0 => "Overweight",
_ => "Obese"
}
}
fn bmi(weight: u32, height: f32) -> &'static str {
let weight: f32 = weight as f32;
let bmi = weight / (height.powi(2));
if bmi <= 18.5 {
return "Underweight"
} else if bmi <= 25.0 {
return "Normal"
} else if bmi <= 30.0 {
return "Overweight"
}
return "Obese";
}
#[test]
fn default_unit_tests() {
assert_eq!(bmi(50, 1.80), "Underweight");
assert_eq!(bmi(80, 1.80), "Normal");
assert_eq!(bmi(90, 1.80), "Overweight");
assert_eq!(bmi(110, 1.80), "Obese");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment