Skip to content

Instantly share code, notes, and snippets.

@jamlfy
Created July 6, 2016 03:14
Show Gist options
  • Save jamlfy/8269811afd298e12977e582ec3799b73 to your computer and use it in GitHub Desktop.
Save jamlfy/8269811afd298e12977e582ec3799b73 to your computer and use it in GitHub Desktop.
Calculadora
//
// 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