Created
May 19, 2019 13:39
-
-
Save shakyra/342be313a2e35e5ad0eb1c6252720be7 to your computer and use it in GitHub Desktop.
Write function bmi that calculates body mass index (bmi = weight / height ^ 2). if bmi <= 18.5 return "Underweight" if bmi <= 25.0 return "Normal" if bmi <= 30.0 return "Overweight" if bmi > 30 return "Obese"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func bmi(_ weight: Int, _ height: Double) -> String { | |
let bmi = Double(weight) / (height * height) | |
if (bmi <= 18.5) { | |
return "Underweight" | |
} | |
else if (bmi <= 25.0) { | |
return "Normal" | |
} | |
else if (bmi <= 30.0) { | |
return "Overweight" | |
} | |
else if (bmi > 30.0) { | |
return "Obese" | |
} | |
else { | |
return "" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment