Jump to content

Programming Fundamentals/Variables/Go

From Wikiversity

variables.go

[edit | edit source]
// 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 | edit source]

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 | edit source]