Used the -As parameter with Read-Host to ensure the correct data type is obtained. Simplified the gender check using the -eq operator. Adjusted the formula by separating terms with multiplication in the BMR calculation. Consolidated the nutrient intake calculation for both genders. Removed unnecessary Exit-PSSession at the end.
30 lines
1.0 KiB
PowerShell
30 lines
1.0 KiB
PowerShell
# User input
|
|
$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")
|
|
{
|
|
$Calories = 655.1 + (9.563 * $Weight) + (1.850 * $Height) - (4.676 * $Age)
|
|
}
|
|
elseif ($Gender -eq "M")
|
|
{
|
|
$Calories = 66.47 + (13.75 * $Weight) + (5.003 * $Height) - (6.755 * $Age)
|
|
}
|
|
else
|
|
{
|
|
Write-Host "Invalid gender. Exiting."
|
|
Exit
|
|
}
|
|
|
|
$Protein_Cals = ($Calories / 10) * 2
|
|
$Carbs_Cals = ($Calories / 10) * 6
|
|
$Fat_Cals = ($Calories / 10) * 2
|
|
|
|
# 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" |