Programming Fundamentals/Functions/Go
< Programming Fundamentals‎ | Functions
// This program asks the user for a Fahrenheit temperature, // converts the given temperature to Celsius,// and displays the results.//// References://​//​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 Documentation
Last edited on 14 June 2020, at 04:01
Content is available under CC BY-SA 3.0 unless otherwise noted.
Privacy policy
Terms of Use
 Home Random Log in  Settings  Donate  About Wikiversity  Disclaimers