2015-12-03 69 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) 
相關問題