From 881606a27bc70f3136d28375a9ae9b5ba29ad203 Mon Sep 17 00:00:00 2001 From: Igor V Belousov Date: Tue, 11 Jan 2022 23:10:35 +0300 Subject: [PATCH] Chapter 2 - 2.6.1 cf.go --- ch2/cf.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ch2/cf.go diff --git a/ch2/cf.go b/ch2/cf.go new file mode 100644 index 0000000..0870782 --- /dev/null +++ b/ch2/cf.go @@ -0,0 +1,23 @@ +// Cf конвертирует числовой аргумент в температуру +// по Цельсию и Фаренгейту. +package main + +import ( + "fmt" + "mygit.i2g.ru/biv/LearnGoDonovan/ch2/tempconv" + "os" + "strconv" +) + +func main() { + for _, arg := range os.Args[1:] { + t, err := strconv.ParseFloat(arg, 64) + if err != nil { + fmt.Fprintf(os.Stderr, "cf: %v\n", err) + os.Exit(1) + } + f := tempconv.Fahrenheit(t) + c := tempconv.Celsius(t) + fmt.Printf("%s = %s, %s = %s\n", f, tempconv.FToC(f), c, tempconv.CToF(c)) + } +}