I have a menu option with two options: add and substract. When I choose one it runs ok but the program closes. I would like to know how to make it go back to the menu after an operation ends to select another one
package main
import (
"fmt"
)
func main() {
var n1, n2, s, r float64
var op, ns int
fmt.Println("
\tWelcome")
fmt.Println("Chose an option")
fmt.Println("1.-Add")
fmt.Println("2.-Substract")
fmt.Scan(&op)
if op == 1 {
fmt.Printf("
\tAdd")
fmt.Printf("
How 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("
Type the number %d: ", i+1)
fmt.Scan(&n1)
s += n1
}
fmt.Println("
The sum is: ", s)
//How to return to the menu?
}
} else if op == 2 {
fmt.Printf("
\tSubtraction")
fmt.Printf("
Type the first number: ")
fmt.Scan(&n1)
fmt.Printf("
Type the second number: ")
fmt.Scan(&n2)
r = n1 - n2
fmt.Println("
Substraction is: ", r)
}
}