diff --git a/playground/countVotes.go b/playground/countVotes.go new file mode 100644 index 0000000..7148dbf --- /dev/null +++ b/playground/countVotes.go @@ -0,0 +1,19 @@ +// from Chapter 7 of Head First Go +package main + +import ( + "fmt" + "git.linuxhg.com/john-okeefe/datafile" + "git.linuxhg.com/john-okeefe/keyboard" + "strings" +) + +func countVotes() { + fmt.Printf("What is the name of the file: ") + fileString, err := keyboard.GetString() + Error(err) + fileString = strings.TrimSpace(fileString) + lines, err := datafile.GetStrings(fileString) + Error(err) + fmt.Println(lines) +} diff --git a/playground/playground.go b/playground/playground.go index a6ff5cb..89de8ed 100644 --- a/playground/playground.go +++ b/playground/playground.go @@ -38,6 +38,8 @@ func main() { slices() case "Variadic Functions": variadic() + case "Count Votes": + countVotes() } return nil }) @@ -55,6 +57,7 @@ func main() { menu.Option("Get the Average Variadic", nil, false, nil) menu.Option("Slices", nil, false, nil) menu.Option("Variadic Functions", nil, false, nil) + menu.Option("Count Votes", nil, false, nil) err := menu.Run() if err != nil { log.Fatal(err)