我創建了這個程序package mainimport "fmt"var bankAccount = 12342func 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 withdraw(withdraw) != 0 { fmt.Println("Not succesful: not enough money (you're broke)") } case 2: fmt.Scanln(&deposit) deposit(deposit) case 3: os.Exit() }}我不斷得到這個錯誤:不能調用非函數存款(類型int),也不能調用非功能存款(類型int)。
- 2 回答
- 0 關注
- 126 瀏覽
添加回答
舉報
0/150
提交
取消