Created
October 30, 2016 10:01
-
-
Save kiras0518/fbbc318df8c67e258be2e6ce82d1ec92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// Tipcalcultion | |
// | |
// Created by Feng on 2016/10/25. | |
// Copyright © 2016年 Fang. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
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. | |
} | |
@IBOutlet weak var cost: UITextField! | |
@IBOutlet weak var tip: UITextField! | |
@IBOutlet weak var result: UILabel! | |
@IBAction func compute(_ sender: AnyObject) { | |
if(cost.text == "" || tip.text == ""){ | |
result.text = "請輸入金額!" //防呆使用 | |
} else { | |
let thecost = Double(cost.text!) //原始金額 | |
let thetip = Double(tip.text!)!/100 //除以百分比 | |
result.text = String((thecost! * thetip)+thecost!) // (金額*小費) + 金額 = 最終金額 | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment