go-examples/w1d2ex1/main.go
2017-07-07 14:29:36 +02:00

33 lines
733 B
Go

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)
}
}