I am trying to have a scene in my app that allows the user to enter numbers in two separate Text Fields, which does some basic math, and spits out the output into a Label when the click the "Calculate button". I have watched videos, changed code, and I can't seem to get it to work the way I want to, and my app keeps crashing. Here is the simple code I have so far. Can anyone explain what I'm entering in that is wrong and what I need to change? It will be much appreciated, Thanks!
import UIKit
class DopamineCalculator: UIViewController {
//Patient weight Input
@IBOutlet weak var patientWeight: UITextField!
//calculate button
@IBAction func calculateButton(sender: AnyObject) {
let weightPatient = Double(self.patientWeight.text!)
dripAnswer.text = String(weightPatient * 2)
}
//Clear button action
@IBAction func clearButton(sender: AnyObject) {
self.patientWeight.text=nil
//self.dosageDesired.text=nil
self.dripAnswer.text=nil
}
//Drip Rate Answer Label
@IBOutlet weak var dripAnswer: UILabel!
My "Clear" button works, but I can't get the "Calculate" button to work. I'm trying to keep it simple for now and just add the two boxes, but i can't even get that to work.