在下面的代码中,我试图弄清楚为什么最后的两行显示为错误。
var account1 = ("State bank personal, 1011.10")
var account2 = ("State bank business, 24309.63")
func deposit(amount : Double, account : (name : String, balance : Double)) -> (String, Double) {
let newBalance : Double = account.balance + amount
return (account.name, newBalance)
}
func withdraw(amount : Double, account : (name : String, balance : Double)) -> (String, Double) {
let newBalance : Double = account.balance - amount
return (account.name, newBalance)
}
var mondayTransaction = deposit
var fridayTransaction = withdraw
let mondayBalance = mondayTransaction(300.0, account1)
let fridayBalace = fridayTransaction(1200.0, account2)
答案 0 :(得分:1)
你前两行没有平衡。您将金额作为名称的一部分。试试这个:
var account1 = ("State bank personal", 1011.10)
var account2 = ("State bank business", 24309.63)