Last active
November 27, 2019 10:01
-
-
Save zamuro/547720a87cecad69fa6c332af1413f21 to your computer and use it in GitHub Desktop.
A simple program in Go to determine how many layers of clothing do I need and a convenient ºC to ºF converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
func calculate (inpt string) { | |
a, _ := strconv.ParseFloat(inpt, 64) | |
if (a < 15 && a >= 10) { | |
fmt.Println("one thin layer") | |
} else if (a < 10 && a >= 5) { | |
fmt.Println("two thin layers or a thick layer") | |
} else if (a < 5 && a >= 0) { | |
fmt.Println("two thick layers or a snow jacket") | |
} else if (a < 0) { | |
fmt.Println("snow jacket and another layer") | |
} | |
cToF(a) | |
} | |
func cToF (c float64) { | |
f := (c * 9 / 5) + 32 | |
fmt.Printf("it's %f degrees Farenheit\n", f) | |
} | |
func main() { | |
fmt.Print("value: ") | |
var inpt string | |
_, err := fmt.Scanf("%s", &inpt) | |
if err != nil { | |
fmt.Println(err) | |
} | |
calculate(inpt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment