go-examples/w1d2ex1/main.go

33 lines
733 B
Go
Raw Normal View History

2017-07-07 12:29:36 +00:00
package main
import "fmt"
import "os"
import "strconv"
var miles float64
const (
MilesToKm float64 = 1.609344
width = 20
titleMiles = "| Miles: "
titleKm = "| Km: "
)
func main() {
if miles, err := strconv.ParseFloat(os.Args[1], 64); err == nil {
fmtMiles := strconv.FormatFloat(miles, 'f', 2, 64)
fmtKm := strconv.FormatFloat(miles*MilesToKm, 'f', 2, 64)
fmt.Println("<!DOCTYPE html>")
fmt.Println("<html>")
fmt.Println(" <head><title>Miles to Kilometers</title></head>")
fmt.Println(" <body>")
fmt.Println(" <p>Miles:", fmtMiles, "</p>")
fmt.Println(" <p>Kilometers:", fmtKm, "</p>")
fmt.Println(" </body>")
fmt.Println("</html>")
} else {
panic(err)
}
}