小编Qui*_*aan的帖子

不能调用非函数withdraw (type int) 是什么意思?

我创建了这个程序

package main

import "fmt"

var bankAccount = 12342

func withdraw(withdrawAmnt int) int { //withdraw function, return int
    bankAccount -= withdrawAmnt
    if bankAccount < 0 {
        bankAccount += withdrawAmnt //bankaccount cannot go negative
        return 1
    } else { return 0 }
}

func deposit(depositAmnt int) {
    bankAccount += depositAmnt
}

func main() {
    var choice int
    var withdraw int
    var deposit int
    fmt.Printf("%d \n 1. withdraw \n 2. deposit \n 3. exit")
    fmt.Scanln(&choice)
    switch choice {
        case 1:
            fmt.Scanln(&withdraw)
            if …
Run Code Online (Sandbox Code Playgroud)

go

-2
推荐指数
1
解决办法
4077
查看次数

标签 统计

go ×1