Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Created November 15, 2015 01:59
Show Gist options
  • Save takaheraw/c207f27c7b1a5ee29573 to your computer and use it in GitHub Desktop.
Save takaheraw/c207f27c7b1a5ee29573 to your computer and use it in GitHub Desktop.
class Calculator {
private (set) var total = 0
func add(amount: Int) {
total += amount
}
func subtract(amount: Int) {
total -= amount
}
func multiply(amount: Int) {
total = total * amount
}
func divide(amount: Int) {
total = total / amount
}
}
let calc = Calculator()
calc.add(10)
calc.multiply(4)
calc.subtract(2)
print("Total: \(calc.total)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment