Initial commit
This commit is contained in:
@ -0,0 +1,42 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
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))
|
||||
return
|
||||
}
|
||||
|
||||
arg := os.Args[1]
|
||||
|
||||
feet, err := strconv.ParseFloat(arg, 64)
|
||||
if err != nil {
|
||||
fmt.Printf("error: '%s' is not a number.\n", arg)
|
||||
return
|
||||
}
|
||||
|
||||
meters := feet * 0.3048
|
||||
|
||||
fmt.Printf("%g feet is %g meters.\n", feet, meters)
|
||||
}
|
Reference in New Issue
Block a user