From 3b19acfebd73e627f70c976cabb22110f222d1da Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Sun, 18 Nov 2018 11:44:50 +0300 Subject: [PATCH] add: exercise solution to numbers cels to fahr --- .../exercise-solution/main.go | 18 ++++++++++++++++++ .../01-numbers/exercises/03-precedence/main.go | 1 + 2 files changed, 19 insertions(+) create mode 100644 08-numbers-and-strings/01-numbers/06-project-feet-to-meters/exercise-solution/main.go diff --git a/08-numbers-and-strings/01-numbers/06-project-feet-to-meters/exercise-solution/main.go b/08-numbers-and-strings/01-numbers/06-project-feet-to-meters/exercise-solution/main.go new file mode 100644 index 0000000..0f8cace --- /dev/null +++ b/08-numbers-and-strings/01-numbers/06-project-feet-to-meters/exercise-solution/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "os" + "strconv" +) + +func main() { + c, _ := strconv.ParseFloat(os.Args[1], 64) + f := c*1.8 + 32 + + // Like this: + fmt.Printf("%g ºC is %g ºF\n", c, f) + + // Or just like this (both are correct): + fmt.Printf("%g ºF\n", f) +} diff --git a/08-numbers-and-strings/01-numbers/exercises/03-precedence/main.go b/08-numbers-and-strings/01-numbers/exercises/03-precedence/main.go index a046804..63a7659 100644 --- a/08-numbers-and-strings/01-numbers/exercises/03-precedence/main.go +++ b/08-numbers-and-strings/01-numbers/exercises/03-precedence/main.go @@ -38,5 +38,6 @@ func main() { fmt.Println(10 / 2 * 10 % 7) // This expression should print 40 + // Note that you may need to use floats to solve this fmt.Println(100 / 5 / 2) }