why my codes wrong? I need in calculator to make % what can I do for it?

hi all
 
//  ViewController.swift
// calculator
//
// Created by shoto chinchaladze on 12/13/16.
// Copyright © 2016 shoto chinchaladze. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

//MARK: - IBOutlets
@IBOutlet var firstNum: UITextField!
@IBOutlet var math: UITextField!
@IBOutlet var secondNum: UITextField!
@IBOutlet var myLabel: UILabel!


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - IBAction
@IBAction func calculate(sender: UIButton){
let firstValue = Float(firstNum.text!)!
let secondValue = Float(secondNum.text!)!
let mathValue = math.text!
var result = Float(0.0)

//MARK: - switch
switch mathValue {
case "+":
result = firstValue + secondValue
case "-":
result = firstValue - secondValue
case "*":
result = firstValue * secondValue
case "/":
result = firstValue / secondValue
case "%":
result = firstValue % secondValue
default:
break
}
myLabel.text = "\(result)"

}

}

 
why its wrong?
I need in calculator to make % what can I do for it?
it crushes my program and why?
can you help me?
You already invited:

sinkync

Upvotes from:

var firstValue = Float()
if let firstNum = firstNum.text {
firstValue = Float(firstNum)!
}
implement this all outlets
I think its safer
and prevent crashes
 
 

If you wanna answer this question please Login or Register