Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // countdown project main.go
- /*
- Why doesn't this 30-liner work?
- I'd do the same thing in the shell.
- Of course not as float, but I want
- to be able to enter 1. 5 hours later, for example, or in yoctoseconds.
- */
- package main
- import (
- "fmt"
- "math"
- "os"
- "strconv"
- "time"
- )
- func countdown(secs float64) {
- for secs >= 0.0 {
- 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))
- secs = secs - 1.0
- time.Sleep(time.Second)
- }
- return
- }
- func main() {
- str1 := os.Args[1]
- floatStr1, err := strconv.ParseFloat(str1, 64)
- if err != nil {
- fmt.Printf("not working \n")
- }
- countdown(floatStr1)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement