Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // BMICalc
- //
- // Created by Seminar User on 2017/08/23.
- // Copyright ยฉ 2017ๅนด i-MOS. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var weightTextField: UITextField!
- @IBOutlet weak var heightTextField: UITextField!
- @IBOutlet weak var resultLabel: 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.
- }
- @IBAction func calcAtion(_ sender: Any) {
- guard let weightString = weightTextField.text else {
- return
- }
- guard let heightString = heightTextField.text else {
- return
- }
- let weight = Double(weightString)
- let height = Double(heightString)
- if let weight = weight {
- if let height = height {
- let result = weight / (height/100.0 * height/100.0)
- resultLabel.text = String(result)
- self.view.endEditing(true)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement