From b616a5ce5d2070c2ac2cb7c38896d2cdba7f45a0 Mon Sep 17 00:00:00 2001 From: Ross Healy Date: Fri, 16 Feb 2024 11:10:38 +0000 Subject: [PATCH] Organized/made more readable, see extended description for full set of changes. 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. --- Nutrition/splits.ps1 | 55 +++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/Nutrition/splits.ps1 b/Nutrition/splits.ps1 index e88e3a3..1859dcb 100644 --- a/Nutrition/splits.ps1 +++ b/Nutrition/splits.ps1 @@ -1,33 +1,30 @@ -#VARS -[decimal]$Weight = Read-Host "Please input weight in kg" -[decimal]$Height = Read-Host "Please input height in cm" -[decimal]$Age = Read-Host "Please input age in years" -[char]$Gender = Read-Host "Are you Male (M) or Female (F)".ToUpper() +# 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() } -#determining split (female) -if ($Gender = "F") { - $Calories = 655.1 + (9.563 * $weight) + (1.850 + $Height) - (4.676 * $Age) - - $Protein_Cals = ($Calories/10)*2 - $Carbs_Cals = ($Calories/10)*6 - $Fat_Cals = ($Calories/10)*2 - 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" +# Calculate BMR and nutrient intake +if ($Gender -eq "F") +{ + $Calories = 655.1 + (9.563 * $Weight) + (1.850 * $Height) - (4.676 * $Age) } -#determing split (male) -elseif ($Gender = "M") { - $Calories = 66.47 + (13.75 * $weight) + (5.003 + $Height) - (6.755 * $Age) - $Protein = $Calories/4 - $Carbs = $Calories/4 - $Fats = $Calories/9 - Write-Host "Your BMR is: " $Calories - Write-Host "Your recommended protein intake is: " $Protein - Write-Host "Your recommended carbohydrate intake is: " $Carbs - Write-Host "Your recommended fat intake is: " $Fats +elseif ($Gender -eq "M") +{ + $Calories = 66.47 + (13.75 * $Weight) + (5.003 * $Height) - (6.755 * $Age) } -else { - Exit-PSSession +else +{ + Write-Host "Invalid gender. Exiting." + Exit } -Exit-PSSession \ No newline at end of file + +$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" \ No newline at end of file