0
06
41
17
为了账号安全,请及时绑定邮箱和手机立即绑定

返回菜单语言 GO

返回菜单语言 GO

Go
慕的地8271018 2021-06-27 07:14:01
我有一个带有两个选项的菜单选项:添加和减去。当我选择一个它运行正常但程序关闭。我想知道如何在操作结束后返回菜单以选择另一个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)    }}
查看完整描述

2 回答

?
小唯快跑啊

TA贡献1863条经验 获得超2个赞

把整个东西都包起来


for {


}

使用break退出循环或continue返回到顶部。


查看完整回答
反对 回复 2021-07-05
?
湖上湖

TA贡献2003条经验 获得超2个赞

如果没有看到您的代码,很难准确判断,但我可能认为您应该使用运算符for ;; {}并将适当的if/else语句放入菜单中。


查看完整回答
反对 回复 2021-07-05

没有找到匹配的内容?试试慕课网站内搜索吧

添加回答

代码语言

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号