Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.70 KB | None | 0 0
  1. // countdown project main.go
  2. /*
  3.     Why doesn't this 30-liner work?
  4.     I'd do the same thing in the shell.
  5.     Of course not as float,  but I want
  6.     to be able to enter 1. 5 hours later, for example, or in yoctoseconds.
  7. */
  8. package main
  9.  
  10. import (
  11.     "fmt"
  12.     "math"
  13.     "os"
  14.     "strconv"
  15.     "time"
  16. )
  17.  
  18. func countdown(secs float64) {
  19.     for secs >= 0.0 {
  20.         fmt.Printf("\r%02.0f day(s) %02.0f:%02.0f:%02.0f", secs/86400.0, secs/3600.0, math.Mod((secs/60.0), 60.0), math.Mod(secs, 60.0))
  21.         secs = secs - 1.0
  22.         time.Sleep(time.Second)
  23.     }
  24.     return
  25. }
  26. func main() {
  27.     str1 := os.Args[1]
  28.     floatStr1, err := strconv.ParseFloat(str1, 64)
  29.     if err != nil {
  30.         fmt.Printf("not working \n")
  31.     }
  32.     countdown(floatStr1)
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement