2015-12-03 76 views
1

在下面的代码中,我想弄清楚为什么最后2行显示为错误。不能将类型'字符串'的值转换为期望的参数类型'(名称:字符串,余额:双)'

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) 

回答

1

你前两行没有余额。您将该金额作为名称的一部分。试试这个:

var account1 = ("State bank personal", 1011.10) 
var account2 = ("State bank business", 24309.63) 
相关问题