Skip to content

Instantly share code, notes, and snippets.

@mofodox
Created December 22, 2023 04:16
Show Gist options
  • Save mofodox/8dcf894b2f5188156de9579e7fec5967 to your computer and use it in GitHub Desktop.
Save mofodox/8dcf894b2f5188156de9579e7fec5967 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strings"
)
func main() {
numOfPlayers := 0
index := 1
fmt.Print("Enter number of players: ")
fmt.Scan(&numOfPlayers)
var playerNames []string
for i := index; i <= numOfPlayers; i++ {
var playerName string
fmt.Printf("Enter player %v name: \n", i)
fmt.Scan(&playerName)
playerNames = append(playerNames, playerName)
}
names := strings.Join(playerNames, ", ")
fmt.Printf("Player names are: %s\n", names)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment