gpt4 book ai didi

string - 无法将类型 'String' 的值转换为预期的参数类型 '(name: String, balance: Double)'

转载 作者:行者123 更新时间:2023-11-28 06:54:32 25 4
gpt4 key购买 nike

在下面的代码中,我试图找出为什么末尾的两行显示为错误。

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)

最佳答案

前两行没有余额。您将金额包含在名称中。试试这个:

var account1 = ("State bank personal", 1011.10)
var account2 = ("State bank business", 24309.63)

关于string - 无法将类型 'String' 的值转换为预期的参数类型 '(name: String, balance: Double)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34056000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com