gpt4 book ai didi

swift - 二元运算符 "=="不能应用于 (Int, Int, Int, Int) -> Int 类型的操作数

转载 作者:行者123 更新时间:2023-11-30 12:32:52 30 4
gpt4 key购买 nike

var a11: Int = 0
var a12: Int = 0
var a21: Int = 0
var a22: Int = 0

var valueDeterminant = a11 * a12 * a21 + a22

func calculateDeterminant(a11: Int, a12: Int, a21: Int, a22: Int) -> Int {
return valueDeterminant
}


if calculateDeterminant == 0 {
print("The trasformation is irreversable, due to the fact that the determinant is \(calculateDeterminant)")
} else if calculateDeterminant == 1 {
print("The determinant is\(calculateDeterminant) \nThe trasformation is reverable, and it keeps the area")
} else {
print("The determinant is \(calculateDeterminant) \nThe transformation is reversable")
}

该错误表示二元运算符 == 不能用于 (Int, Int, Int, Int) 类型。为什么?我该如何解决这个问题?另外,如果我将返回值更改为 Bool,则会出现另一个错误,指出我无法输入返回 Bool 值的 Int 值。

最佳答案

函数是一流的值。您正在将函数 calculateDeterminantInt 进行比较。不支持。调用该函数,然后比较整数值。

var a11: Int = 0
var a12: Int = 0
var a21: Int = 0
var a22: Int = 0

var valueDeterminant = a11 * a12 * a21 + a22

func calculateDeterminant() -> Int {
return a11 * a12 * a21 * a22
}


if calculateDeterminant() == 0 {
print("The trasformation is irreversable, due to the fact that the determinant is \(calculateDeterminant())")
} else if calculateDeterminant() == 1 {
print("The determinant is\(calculateDeterminant()) \nThe trasformation is reverable, and it keeps the area")
} else {
print("The determinant is \(calculateDeterminant()) \nThe transformation is reversable")
}

或者像这样定义它......

func calculateDeterminant(a11: Int, a12: Int, a21: Int, a22: Int) -> Int {
return a11 * a12 * a21 * a22
}

...并这样调用它。

if (calculateDeterminant(a11: a11, a12: a12, a21: a21, a22: a22) == 0 {...}

关于swift - 二元运算符 "=="不能应用于 (Int, Int, Int, Int) -> Int 类型的操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43265848/

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