Created
December 9, 2019 00:17
-
-
Save PatrickHoward/6314467c91f582d9ab4dcbcfb5b26cb6 to your computer and use it in GitHub Desktop.
A quick reimplementation of a calorie counter program written in C++ now in Rust.
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
use std::io; | |
fn main() { | |
const KILO_PER_POUND:f32 = 2.2; | |
const CALORIE_BURN_RATE:f32 = 0.0175; | |
println!("Input your weight in pounds: "); | |
let mut weight_in_pounds = String::new(); | |
io::stdin().read_line(&mut weight_in_pounds).expect("Please input a valid string"); | |
let weight_in_pounds:f32 = weight_in_pounds.trim().parse().expect("Weight is not a number"); | |
let weight_in_kilos = weight_in_pounds / KILO_PER_POUND; | |
println!("Input metabolic equivalent rate: "); | |
let mut metabolic_rate = String::new(); | |
io::stdin().read_line(&mut metabolic_rate).expect("Please input a valid string"); | |
let metabolic_rate:f32 = metabolic_rate.trim().parse().expect("Metabolic rate is not a number"); | |
println!("Input time spent, in minutes: "); | |
let mut time_in_minutes = String::new(); | |
io::stdin().read_line(&mut time_in_minutes).expect("Please input a valid string"); | |
let time_in_minutes: f32 = time_in_minutes.trim().parse().expect("Time is not a number"); | |
let calorie_rate = CALORIE_BURN_RATE * metabolic_rate * weight_in_kilos; | |
let total_calories_burned = calorie_rate * time_in_minutes; | |
println!("You burned a total of {} at a rate of {} per minute.", total_calories_burned, calorie_rate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment