Go 我的div(4,2)程序应该返回(0,true),而div(4,3)应该返回(1,false)的程序给出了错误

Go 我的div(4,2)程序应该返回(0,true),而div(4,3)应该返回(1,false)的程序给出了错误,go,Go,我的div4,2程序应该返回0,true,div4,3应该返回1,false package main import "fmt" func div(a int, b int) (int, bool) { if a%b == 0 { c := a % b return c, true } else { c := a % b return c, true } } func main() { fmt.

我的div4,2程序应该返回0,true,div4,3应该返回1,false

package main

import "fmt"

func div(a int, b int) (int, bool) {
    if a%b == 0 {
        c := a % b
        return c, true
    } else {
        c := a % b
        return c, true
    }
}

func main() {
    fmt.Println(div(4, 2)) // should return (0, true)
    fmt.Println(div(4, 3)) // should return (1, false)
}
游乐场:

输出:

0 true
1 true
0 true
1 false
0 true
1 false
比如说,

package main

import "fmt"

func div(a int, b int) (int, bool) {
    if a%b == 0 {
        c := a % b
        return c, true
    } else {
        c := a % b
        return c, false
    }
}

func main() {
    fmt.Println(div(4, 2)) // should return (0, true)
    fmt.Println(div(4, 3)) // should return (1, false)
}
游乐场:

输出:

0 true
1 true
0 true
1 false
0 true
1 false
或者简单地说

package main

import "fmt"

func div(a int, b int) (int, bool) {
    c := a % b
    return c, c == 0
}

func main() {
    fmt.Println(div(4, 2)) // should return (0, true)
    fmt.Println(div(4, 3)) // should return (1, false)
}
游乐场:

输出:

0 true
1 true
0 true
1 false
0 true
1 false

给出以下错误:这是一个打字错误还是你应该写的是真的?我想真是一个真正的打字错误。如果是,则If语句的两个分支都返回true。这两个分支都不返回false。如果您的代码给出了错误,那么在您的问题中包含该错误是很重要的。谢谢Peter,它非常有效