Created
November 15, 2023 15:27
-
-
Save metacritical/dd7ad1579729042855e8f41ffd330d26 to your computer and use it in GitHub Desktop.
Total Daily Energy Expenditure script
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
#!/usr/bin/env ruby | |
# Function to calculate BMR | |
def calculate_bmr(gender, weight, height, age) | |
if gender.downcase == 'male' | |
return 88.362 + (13.397 * weight) + (4.799 * height) - (5.677 * age) | |
else | |
return 447.593 + (9.247 * weight) + (3.098 * height) - (4.330 * age) | |
end | |
end | |
# User input | |
puts "Enter your gender (male/female):" | |
gender = gets.chomp | |
puts "Enter your age (years):" | |
age = gets.to_i | |
puts "Enter your weight (kg):" | |
weight = gets.to_f | |
puts "Enter your height (cm):" | |
height = gets.to_f | |
puts "Enter your activity level (1.2 for sedentary, 1.375 for lightly active, 1.55 for moderately active, 1.725 for very active, 1.9 for extra active):" | |
activity_level = gets.to_f | |
# Calculate BMR | |
bmr = calculate_bmr(gender, weight, height, age) | |
# Calculate TDEE | |
tdee = bmr * activity_level | |
puts "Your Total Daily Energy Expenditure (TDEE) is: #{tdee.round(2)} calories/day." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment