Added calculate-BMI.ps1

This commit is contained in:
Markus Fleschutz
2025-07-24 17:40:02 +02:00
parent cebd264a9e
commit f448fa660c

25
scripts/calculate-BMI.ps1 Normal file
View File

@ -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
}