// // ViewController.swift // Simple Calculator // import UIKit class ViewController: UIViewController { // FINISH ME // create (define) a variable called whichNumber and set it to 1 // this controls which field has the focus ??? ??????? = ? // FINISH ME // Control + Drag the Number 1 TextField to here @IBOutlet weak var number1TextField: UITextField! // FINISH ME // Control + Drag the Op Label to here @IBOutlet weak var opLabel: UILabel! // FINISH ME // Control + Drag the Number 2 TextField to here @IBOutlet weak var number2TextField: UITextField! // FINISH ME // Control + Drag the answerLabel Label to here @IBOutlet weak var answerLabel: UILabel! // FINISH ME // Control + Drag the Number 1 TextField to here // NOTE: This is a Touch Down Action Event @IBAction func number1TouchDownEvent(_ sender: UITextField) { // FINISH ME // set whichNumber to 1 // which indicates number1TextField has the focus whichNumber = 1 } // FINISH ME // Control + Drag the Number 2 TextField to here // NOTE: This is a Touch Down Action Event @IBAction func number2TouchDownEvent(_ sender: UITextField) { // FINISH ME // set whichNumber to 2 // which indicates number2TextField has the focus whichNumber = 2 } // FINISH ME // Control + Drag each digit Button to here @IBAction func digitButtonEvent(_ sender: UIButton) { // here we get the digit on the digit button let digitOnButton = sender.title(for: .normal)! print(whichNumber) // for testing only if whichNumber == 1 { // FINISH ME // join on digitOnButton number1TextField.text = number1TextField.text! + ????? } else if whichNumber == 2 { // FINISH ME // join on digitOnButton number2TextField.text = number2TextField.text! + ????? } } // FINISH ME // Control + Drag the clear Button here @IBAction func clearButtonEvent(_ sender: UIButton) { // FINISH ME // set number1TextField to "" number1TextField.???? = "" // FINISH ME // set number2TextField to "" ???? // FINISH ME // set answerLabel to "" ????? // FINISH ME // set opLabel to "+" ??????? } // FINISH ME // Control + Drag each operator button to this function (method) @IBAction func opButtonEvent(_ sender: UIButton) { // sender is the temporary name of the button // that was clicked // this gets the text on the button that // got clicked, which is the operator + or - or * or / or % or ^ let opOnButton = sender.title(for: .normal)! // FINISH ME // check and see if opOnButton is equal to a "+" if opOnButton == "+" { opLabel.text = "+" } // FINISH ME // check and see if opOnButton is equal to a "-" else if opOnButton == "-" { // FINISH ME // set the text of opLabel to "-" ????? } // FINISH ME // create the other else if statements for *, /, %, and ^ else if opOnButton == "*" { // FINISH ME // set the text of opLabel to "*" ??????? } else if opOnButton == "/" { // FINISH ME // set the text of opLabel to "/" ?????? } else if opOnButton == "%" { // FINISH ME // set the text of opLabel to "%" ??????? } } // FINISH ME // LINK the Enter button to this function @IBAction func enterButtonEvent(_ sender: UIButton) { // FINISH ME // convert the number1TextField.text! to an Int let firstNumber = ???(number1TextField.????!) // FINISH ME // Get the text on the opLabel (and we unwrap it) let op = ?????.????! // FINISH ME // convert the number2TextField.text! to an Int let secondNumber = ???(number2TextField.????!) // FINISH ME // create the shadow variables for firstNumber and secondNumber if let ?????? = firstNumber, let ????? = secondNumber { // FINISH ME // check and see if op is a "+" if ?? == ??? { // FINISH ME // add firstNumber and secondNumber let result = ?????? // FINISH ME // set the text field of answerLabel to the result as a String answerLabel.???? = ?????(result) } // FINISH ME // check and see if op is a "-" else ?? ?? == ??? { // FINISH ME // subtract secondNumber from firstNumber let result = firstNumber - secondNumber // FINISH ME // set the text field of answerLabel to the result as a String // answerLabel.???? = ?????(result) } // FINISH ME // check and see if op is a "*" else ?? ?? == ??? { // FINISH ME // multiply firstNumber and secondNumber let result = firstNumber * secondNumber // FINISH ME // convert result to a String // ?????? } // FINISH ME // check and see if op is a "/" else ?? ?? == ??? { // FINISH ME // divide firstNumber by secondNumber let result = firstNumber / secondNumber // FINISH ME // convert the result to a String // ??????? } // FINISH ME // check and see if op is a "%" (modulus) else ?? ?? == ??? { // FINISH ME // modulus firstNumber by secondNumber let result = firstNumber % secondNumber // FINISH ME // convert result to a String // ????? } } else { // FINISH ME // put an error message on the answerLabel // answerLabel.???? = "??????????" } } // DO NOT CHANGE THIS override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } } // END OF CLASS MARKER