Initial commit

This commit is contained in:
Inanc Gumus
2018-10-13 23:30:21 +03:00
commit cde4e6632c
567 changed files with 17896 additions and 0 deletions

View File

@ -0,0 +1,52 @@
// 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"
)
// ---------------------------------------------------------
// CHALLENGE
// Add error handling to the feet to meters program.
//
// EXPECTED OUTPUT
// go run main.go hello
// error: 'hello' is not a number.
//
// go run main.go what
// error: 'what' is not a number.
//
// go run main.go 100
// 100 feet is 30.48 meters.
// ---------------------------------------------------------
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, _ := strconv.ParseFloat(arg, 64)
meters := feet * 0.3048
fmt.Printf("%g feet is %g meters.\n", feet, meters)
}