Examples · learn/05-structs · 113 of 339
task-3.solution
tin run examples/learn/05-structs/task-3.solution.tintype Money = { euros: int, cents: int }
fn Money.plus(a: Money, b: Money): Money {
let total = (a.euros + b.euros) * 100 + a.cents + b.cents
Money { euros: total / 100, cents: total % 100 }
}
fn main() {
let coffee = Money { euros: 3, cents: 80 }
let cake = Money { euros: 4, cents: 50 }
let bill = coffee.plus(cake)
print("{bill.euros}.{"{bill.cents}".padLeft(2, "0")}")
}