Skip to content

Instantly share code, notes, and snippets.

@zamuro
Last active November 27, 2019 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zamuro/547720a87cecad69fa6c332af1413f21 to your computer and use it in GitHub Desktop.
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
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