Solution Review: Temperature Conversion
This lesson discusses the solution to the challenge given in the previous lesson.
We'll cover the following...
We'll cover the following...
Go (1.6.2)
Saved
package mainimport ("fmt")// aliasing typetype Celsius float32type Fahrenheit float32// Function to convert celsius to fahrenheitfunc toFahrenheit(t Celsius) Fahrenheit {return Fahrenheit((t*9/5 )+ 32)}func main() {var tempCelsius Celsius = 100tempFahr := toFahrenheit(tempCelsius) // function callfmt.Printf("%f ˚C is equal to %f ˚F",tempCelsius,tempFahr)}
-
Lines 7-8: We aliased the types of the temperature, i.e.,
float32toCelsiusandFahrenheit. At line 7, we alias the type float 32 by giving the nameCelsius. We need another type calledFahrenheit, ...