ios - Xcode "Cannot convert return expression of type 'String' to return type 'Float'" -


i trying create bmi calculator takes user's height , weight inputs calculates bmi; there, uses series of if-else statements return message user states if healthy/over/underweight. have no problem getting program return calculated bmi value; when incorporate if-else statement, "cannot convert return expression of type 'string' return type 'float'" error.

here's code (i've done 1 if-else statement far):

import uikit  func bodymassindex (userheight : float, userweight : float) -> string {      let userheightsquared = (userheight*userheight)      let userweight = userweight      let userbmi = (userweight/userheightsquared)      return userbmi      if userbmi > 25 {       return "overweight"     }  }  print(bodymassindex (userheight : 1.82, userweight: 90.7)) 

you have wrap float value of userbmi string.

func bodymassindex (userheight : float, userweight : float) -> string {      let userheightsquared = (userheight*userheight)      let userweight = userweight      let userbmi = (userweight/userheightsquared)      return string(userbmi)      if userbmi > 25 {          return "overweight"      }  } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -