Menu: Difference between revisions
Go solution
(added Fantom example) |
(Go solution) |
||
Line 447:
=={{header|Fantom}}==
<lang fantom>class Main▼
▲<lang fantom>
{
static Void displayList (Str[] items)
Line 484 ⟶ 482:
echo ("You chose: $choice")
}
}</lang>▼
=={{header|Go}}==
<lang go>package main
import "fmt"
var choices = []string{
"fee fie",
"huff and puff",
"mirror mirror",
"tick tock",
}
▲</lang>
func menu(choices []string) string {
if len(choices) == 0 {
return ""
}
var c int
for {
fmt.Println("")
for i, s := range choices {
fmt.Printf("%d. %s\n", i+1, s)
}
fmt.Print("Enter number: ")
_, err := fmt.Scanln(&c)
if err == nil && c > 0 && c <= len(choices) {
break
}
}
return choices[c-1]
}
func main() {
fmt.Println(menu(choices))
}</lang>
=={{header|Haskell}}==
|