Created
July 6, 2016 03:14
-
-
Save jamlfy/8269811afd298e12977e582ec3799b73 to your computer and use it in GitHub Desktop.
Calculadora
This file contains hidden or 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 | |
// Cal | |
// | |
// Created by Alejandro Next on 5/07/16. | |
// Copyright © 2016 alejonext.co. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var resultado: UILabel! | |
var jugador: Int = 0 | |
var cero: Bool = true | |
var operadores: Int = 0 | |
@IBAction func numeroAccion(sender: AnyObject) { | |
if cero { | |
resultado.text = "0" | |
cero = !cero | |
} | |
var fools: Int = Int( resultado.text! )! | |
fools = ( fools * 10 ) + sender.tag! | |
resultado.text = "\(fools)" | |
} | |
@IBAction func borrar(sender: AnyObject) { | |
resultado.text = "0" | |
cero = true | |
operadores = 0 | |
jugador = 0 | |
} | |
@IBAction func operadoresAccion(sender: AnyObject) { | |
let res: Int = Int( resultado.text! )! | |
switch operadores { | |
case 1: | |
jugador = jugador * res | |
case 2: | |
jugador = jugador / res | |
case 3: | |
jugador = jugador + res | |
case 4: | |
jugador = jugador - res | |
default: | |
jugador = res | |
} | |
cero = true | |
operadores = sender.tag | |
resultado.text = "\(jugador)" | |
if operadores == 0 { | |
jugador = 0 | |
} | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.borrar(self) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment