Skip to content

Instantly share code, notes, and snippets.

@shakyra
Created May 19, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakyra/342be313a2e35e5ad0eb1c6252720be7 to your computer and use it in GitHub Desktop.
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"
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