Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var calcScreen: UITextField!
- var first = 0
- var second = 0
- var operation = ""
- var answer = 0
- 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 pressedOne(sender: UIButton) {
- calcScreen.text = "1"
- if first == 0 { first = 1} else {second = 1}
- }
- @IBAction func pressedTwo(sender: UIButton) {
- calcScreen.text = "2"
- if first == 0 { first = 2} else {second = 2}
- }
- @IBAction func pressedThree(sender: UIButton) {
- calcScreen.text = "3"
- if first == 0 { first = 3} else {second = 3}
- }
- @IBAction func clearScreen(sender: UIButton) {
- calcScreen.text = ""
- first = 0
- second = 0
- }
- @IBAction func add(sender: UIButton) {
- operation = "add"
- }
- @IBAction func minus(sender: UIButton) {
- operation = "minus"
- }
- @IBAction func equals(sender: UIButton) {
- if operation == "minus"{
- answer = first - second
- calcScreen.text = "\(answer)"
- }
- if operation == "add" {
- answer = first + second
- calcScreen.text = "\(answer)"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement