From f448fa660c2dbc0f0bf96656721e3811f819cf36 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 24 Jul 2025 17:40:02 +0200 Subject: [PATCH] Added calculate-BMI.ps1 --- scripts/calculate-BMI.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 scripts/calculate-BMI.ps1 diff --git a/scripts/calculate-BMI.ps1 b/scripts/calculate-BMI.ps1 new file mode 100644 index 00000000..c4ec5a11 --- /dev/null +++ b/scripts/calculate-BMI.ps1 @@ -0,0 +1,25 @@ +<# +.SYNOPSIS + Calculate the BMI +.DESCRIPTION + This PowerShell script calculates the BMI. +.EXAMPLE + PS> ./calculate-BMI.ps1 +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +#requires -version 5.1 + +try { + [float]$height = Read-Host("Enter your height in m ") + [float]$weight = Read-Host("Enter your weight in kg") + $BMI = $weight / ($height * $height) + "Your BMI is $BMI, for adults the WHO regards <16 as Underweight (severe thinness), 16-17 as Underweight (moderate thinness), 17-18.5 as Underweight (mild thinness), 18.5-25 as Normal range, 25-30 as Overweight (pre-obese), 30-35 as Obese (class I), 35-40 as Obese (class II), and >=40 as Obese (class III)." + exit 0 # success +} catch { + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." + exit 1 +}