Add functionality to calculate BMI and checks BMI categories

This commit is contained in:
2024-02-17 15:32:40 +00:00
parent b616a5ce5d
commit f00098fc4d

View File

@@ -1,20 +1,15 @@
# User input # Input user information
$Weight = Read-Host "Please input weight in kg" -As [decimal] $Weight = Read-Host "Please input weight in kg" -As [decimal]
$Height = Read-Host "Please input height in cm" -As [decimal] $Height = Read-Host "Please input height in cm" -As [decimal]
$Age = Read-Host "Please input age in years" -As [decimal] $Age = Read-Host "Please input age in years" -As [decimal]
$Gender = Read-Host "Are you Male (M) or Female (F)" -As [char] | ForEach-Object { $_.ToString().ToUpper() } $Gender = Read-Host "Are you Male (M) or Female (F)" -As [char] | ForEach-Object { $_.ToString().ToUpper() }
# Calculate BMR and nutrient intake # Calculate BMR and nutrient intake
if ($Gender -eq "F") if ($Gender -eq "F") {
{
$Calories = 655.1 + (9.563 * $Weight) + (1.850 * $Height) - (4.676 * $Age) $Calories = 655.1 + (9.563 * $Weight) + (1.850 * $Height) - (4.676 * $Age)
} } elseif ($Gender -eq "M") {
elseif ($Gender -eq "M")
{
$Calories = 66.47 + (13.75 * $Weight) + (5.003 * $Height) - (6.755 * $Age) $Calories = 66.47 + (13.75 * $Weight) + (5.003 * $Height) - (6.755 * $Age)
} } else {
else
{
Write-Host "Invalid gender. Exiting." Write-Host "Invalid gender. Exiting."
Exit Exit
} }
@@ -23,8 +18,24 @@ $Protein_Cals = ($Calories / 10) * 2
$Carbs_Cals = ($Calories / 10) * 6 $Carbs_Cals = ($Calories / 10) * 6
$Fat_Cals = ($Calories / 10) * 2 $Fat_Cals = ($Calories / 10) * 2
# Calculate BMI and determine BMI category
$BMI = ($Weight / ($Height / 100) / ($Height / 100))
$BMICategory = "Unknown"
if ($BMI -lt 18.5) {
$BMICategory = "Underweight"
} elseif ($BMI -ge 18.5 -and $BMI -lt 24.9) {
$BMICategory = "Normal Weight"
} elseif ($BMI -ge 25 -and $BMI -lt 29.9) {
$BMICategory = "Overweight"
} elseif ($BMI -ge 30) {
$BMICategory = "Obese"
}
# Display results # Display results
Write-Host "Your BMR is: " ([math]::Round($Calories, 0)) Write-Host "Your BMR is: " ([math]::Round($Calories, 0))
Write-Host "Your recommended protein intake is: " ([math]::Round($Protein_Cals, 0)) "kcals" Write-Host "Your recommended protein intake is: " ([math]::Round($Protein_Cals, 0)) "kcals"
Write-Host "Your recommended carbohydrate intake is: " ([math]::Round($Carbs_Cals, 0)) "kcals" Write-Host "Your recommended carbohydrate intake is: " ([math]::Round($Carbs_Cals, 0)) "kcals"
Write-Host "Your recommended fat intake is: " ([Math]::Round($Fat_Cals, 0)) "kcals" Write-Host "Your recommended fat intake is: " ([Math]::Round($Fat_Cals, 0)) "kcals"
Write-Host "Your BMI is: " ([math]::Round($BMI, 2))
Write-Host "Your BMI Category is: $BMICategory"