diff --git a/golangr/counter/main.go b/golangr/counter/main.go index 5403145..e505b08 100644 --- a/golangr/counter/main.go +++ b/golangr/counter/main.go @@ -3,10 +3,11 @@ package main import ( "fmt" "os" + "strconv" "time" ) -var delay float64 +var delay time.Duration var num int16 func clear() { @@ -14,22 +15,20 @@ func clear() { } func main() { - if len(os.Args) != 2 { - fmt.Println("Not enough arguments") + fmt.Println("Usage: ./counter 1000 (measured in miliseconds)") os.Exit(1) } - fmt.Println("How much delay in seconds?") - timer, err := fmt.Scanln(num) - _ = timer + delay, err := strconv.Atoi(os.Args[1]) + if err != nil { - fmt.Println(err) + fmt.Printf("\nERROR:\n%v\n", err) } for i := 0; true; i++ { - time.Sleep(100 * time.Millisecond) clear() fmt.Println(i) + time.Sleep(time.Duration(delay) * time.Millisecond) } }