From 4913df663a7ec54a3fde158c20cf595e803ac36a Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 31 Jan 2024 07:43:11 +0000 Subject: [PATCH] Added counter exercise --- golangr/counter/go.mod | 3 +++ golangr/counter/main.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 golangr/counter/go.mod create mode 100644 golangr/counter/main.go diff --git a/golangr/counter/go.mod b/golangr/counter/go.mod new file mode 100644 index 0000000..dda9c1a --- /dev/null +++ b/golangr/counter/go.mod @@ -0,0 +1,3 @@ +module counter + +go 1.21.6 diff --git a/golangr/counter/main.go b/golangr/counter/main.go new file mode 100644 index 0000000..5403145 --- /dev/null +++ b/golangr/counter/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + "time" +) + +var delay float64 +var num int16 + +func clear() { + fmt.Print("\033[H\033[2J") +} + +func main() { + + if len(os.Args) != 2 { + fmt.Println("Not enough arguments") + os.Exit(1) + } + + fmt.Println("How much delay in seconds?") + timer, err := fmt.Scanln(num) + _ = timer + if err != nil { + fmt.Println(err) + } + + for i := 0; true; i++ { + time.Sleep(100 * time.Millisecond) + clear() + fmt.Println(i) + } +}