From f00098fc4dd1a644a2ab05f52a5c627f522d9f14 Mon Sep 17 00:00:00 2001 From: Ross Healy Date: Sat, 17 Feb 2024 15:32:40 +0000 Subject: [PATCH] Add functionality to calculate BMI and checks BMI categories --- Nutrition/splits.ps1 | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Nutrition/splits.ps1 b/Nutrition/splits.ps1 index 1859dcb..4e77720 100644 --- a/Nutrition/splits.ps1 +++ b/Nutrition/splits.ps1 @@ -1,20 +1,15 @@ -# User input +# Input user information $Weight = Read-Host "Please input weight in kg" -As [decimal] $Height = Read-Host "Please input height in cm" -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() } # 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) -} -elseif ($Gender -eq "M") -{ +} elseif ($Gender -eq "M") { $Calories = 66.47 + (13.75 * $Weight) + (5.003 * $Height) - (6.755 * $Age) -} -else -{ +} else { Write-Host "Invalid gender. Exiting." Exit } @@ -23,8 +18,24 @@ $Protein_Cals = ($Calories / 10) * 2 $Carbs_Cals = ($Calories / 10) * 6 $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 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 carbohydrate intake is: " ([math]::Round($Carbs_Cals, 0)) "kcals" -Write-Host "Your recommended fat intake is: " ([Math]::Round($Fat_Cals, 0)) "kcals" \ No newline at end of file +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" \ No newline at end of file