Files
learngo/11-if/02-if-statement/04-refactor-feet-to-meters/main.go
2019-10-30 19:41:13 +03:00

44 lines
790 B
Go

// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
const usage = `
Feet to Meters
--------------
This program converts feet into meters.
Usage:
feet [feetsToConvert]`
func main() {
if len(os.Args) < 2 {
fmt.Println(strings.TrimSpace(usage))
// ALTERNATIVE:
// fmt.Println("Please tell me a value in feet")
return
}
arg := os.Args[1]
feet, _ := strconv.ParseFloat(arg, 64)
meters := feet * 0.3048
fmt.Printf("%g feet is %g meters.\n", feet, meters)
}