From 276d8b42d3e15835ae4dfa03eec310e61b1b7996 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Tue, 19 Dec 2023 09:24:56 -0500 Subject: [PATCH] added count Votes to playground --- playground/countVotes.go | 19 +++++++++++++++++++ playground/playground.go | 3 +++ 2 files changed, 22 insertions(+) create mode 100644 playground/countVotes.go 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)