Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // BMICalc
  4. //
  5. // Created by Seminar User on 2017/08/23.
  6. // Copyright ยฉ 2017ๅนด i-MOS. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.  
  13. @IBOutlet weak var weightTextField: UITextField!
  14.  
  15. @IBOutlet weak var heightTextField: UITextField!
  16.  
  17. @IBOutlet weak var resultLabel: UILabel!
  18.  
  19.  
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. // Do any additional setup after loading the view, typically from a nib.
  23. }
  24.  
  25. override func didReceiveMemoryWarning() {
  26. super.didReceiveMemoryWarning()
  27. // Dispose of any resources that can be recreated.
  28. }
  29.  
  30. @IBAction func calcAtion(_ sender: Any) {
  31. guard let weightString = weightTextField.text else {
  32. return
  33. }
  34. guard let heightString = heightTextField.text else {
  35. return
  36. }
  37.  
  38. let weight = Double(weightString)
  39. let height = Double(heightString)
  40. if let weight = weight {
  41. if let height = height {
  42. let result = weight / (height/100.0 * height/100.0)
  43. resultLabel.text = String(result)
  44.  
  45. self.view.endEditing(true)
  46. }
  47. }
  48.  
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement