我有一個帶有兩個選項的菜單選項:添加和減去。當我選擇一個它運行正常但程序關閉。我想知道如何在操作結束后返回菜單以選擇另一個package mainimport ( "fmt")func main() { var n1, n2, s, r float64 var op, ns int fmt.Println("\n\tWelcome") fmt.Println("Chose an option") fmt.Println("1.-Add") fmt.Println("2.-Substract") fmt.Scan(&op) if op == 1 { fmt.Printf("\n\tAdd") fmt.Printf("\nHow many numbers you add? ") fmt.Scan(&ns) if ns <= 1 { fmt.Print("You can not add just a number") } else { for i := 0; i < ns; i++ { fmt.Printf("\nType the number %d: ", i+1) fmt.Scan(&n1) s += n1 } fmt.Println("\nThe sum is: ", s) //How to return to the menu? } } else if op == 2 { fmt.Printf("\n\tSubtraction") fmt.Printf("\nType the first number: ") fmt.Scan(&n1) fmt.Printf("\nType the second number: ") fmt.Scan(&n2) r = n1 - n2 fmt.Println("\nSubstraction is: ", r) }}
返回菜單語言 GO
慕的地8271018
2021-06-27 07:14:01