-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A trainee project for my Rust study which calculates BMI for each mmb…
…er of a gim
- Loading branch information
1 parent
e9c4583
commit b86945a
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "Rust_BMI" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::io; | ||
#[derive(Debug)] | ||
struct Client { | ||
name: String, | ||
weight: f32, | ||
height: f32, | ||
diet: String, | ||
condition: String, | ||
} | ||
impl Client { | ||
fn bmi(&self) -> i32 { | ||
//return self.weight / self.height.powf(2.0); | ||
(self.weight * 10000.0 / (self.height * self.height)) as i32 | ||
} | ||
/*fn longevity(&self) -> bool { | ||
if self.diet == "vegan" { | ||
true | ||
} else { | ||
false | ||
} | ||
}*/ | ||
fn health(&mut self) { | ||
match self.bmi() { | ||
x if x > 0 && x <= 18 => self.condition = "underweight range".to_string(), | ||
x if x > 18 && x <= 25 => self.condition = "Healthy Weight range".to_string(), | ||
x if x > 25 && x <= 30 => self.condition = "overweight range".to_string(), | ||
_ => self.condition = "error".to_string(), | ||
} | ||
} | ||
pub fn new() -> Self { | ||
Self { | ||
name: String::new(), | ||
weight: 0.0, | ||
height: 0.0, | ||
diet: String::new(), | ||
condition: String::new(), | ||
} | ||
} | ||
} | ||
fn main() { | ||
let mut members = String::new(); | ||
let mut collection = Vec::new(); | ||
println!("Number of Clients you have:"); | ||
io::stdin() | ||
.read_line(&mut members) | ||
.expect("Entered members are invalid"); | ||
let members: u8 = members.trim().parse().unwrap(); | ||
for _i in 0..members { | ||
let mut babe = Client::new(); | ||
let mut weight = String::new(); | ||
println!("Please enter the client's name"); | ||
io::stdin() | ||
.read_line(&mut babe.name) | ||
.expect("Entered name is invalid"); | ||
println!("Please enter the client weight"); | ||
io::stdin() | ||
.read_line(&mut weight) | ||
.expect("Entered weight is invalid"); | ||
babe.weight = weight.trim().parse().unwrap(); | ||
let mut height = String::new(); | ||
println!("Please enter the client height"); | ||
io::stdin() | ||
.read_line(&mut height) | ||
.expect("Entered height is invalid"); | ||
babe.height = height.trim().parse().unwrap(); | ||
println!("Please enter the client diet"); | ||
io::stdin() | ||
.read_line(&mut babe.diet) | ||
.expect("Entered diet is invalid"); | ||
babe.health(); | ||
collection.push(babe); | ||
} | ||
println!("{:?}", collection); | ||
} |