Programming Fundamentals/Functions/Go
< Programming Fundamentals‎ | Functions
functions.go
// This program asks the user for a Fahrenheit temperature, // converts the given temperature to Celsius,// and displays the results.//// References:// https://www.mathsisfun.com/temperature-conversion.html​// https://golang.org/doc/​package mainimport "fmt"func main() { var fahrenheit = GetFahrenheit() var celsius = CalculateCelsius​(​fahrenheit​) DisplayResult​(​fahrenheit​, celsius)}func GetFahrenheit() float32 { var fahrenheit float32 fmt.Printf("Enter Fahrenheit temperature: ") fmt​.​Scanln​(​&​fahrenheit​) return fahrenheit}func CalculateCelsius​(​fahrenheit float32) float32 { var celsius = (fahrenheit - 32) * 5 / 9 return celsius}func DisplayResult​(​fahrenheit float32, celsius float32) { fmt.Printf("%f° Fahrenheit is %f° Celsius\n", fahrenheit, celsius)}
Try It
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
GoLang.org: Documentation
Last edited on 14 June 2020, at 04:01
Wikiversity
Content is available under CC BY-SA 3.0 unless otherwise noted.
Privacy policy
Terms of Use
Desktop
 Home Random Log in  Settings  Donate  About Wikiversity  Disclaimers
WatchEdit