【发布时间】:2019-06-15 20:37:04
【问题描述】:
尝试将 BMI(体重指数)计算为 Swift 中的应用程序。制作计算函数我找不到解决方案
@IBOutlet weak var height: UITextField!
@IBOutlet weak var weight: UITextField!
@IBAction func calculate(_ sender: UIButton) {
}
@IBAction func reset(_ sender: UIButton) {
}
func calculateIMC(){
var textHeight = height.text
var textWeight = weight.text
var intHeight:Int? = Int(textHeight!) ?? 0
var intWeight:Int? = Int(textWeight!) ?? 0
let calculateHeight: Int? = (intHeight * intHeight)
}
最后一行代码的错误信息:
二元运算符 '*' 不能应用于两个 'Int?'操作数
【问题讨论】: