Programming Fundamentals/Variables/Go

variables.go

edit
// This program converts a Fahrenheit temperature to Celsius.
//
// References:
//     https://www.mathsisfun.com/temperature-conversion.html
//     https://golang.org/doc/

package main

import "fmt"

func main() {
    var fahrenheit float32
    var celsius float32
    
    fmt.Printf("Enter Fahrenheit temperature: ")
    fmt.Scanln(&fahrenheit)

    celsius = (fahrenheit - 32) * 5 / 9

    fmt.Printf("%f° Fahrenheit is %f° Celsius\n", fahrenheit, celsius)
}

Try It

edit

Copy and paste the code above into one of the following free online development environments or use your own Go compiler / interpreter / IDE.

See Also

edit