...

/

Solution Review: Temperature Conversion

Solution Review: Temperature Conversion

This lesson discusses the solution to the challenge given in the previous lesson.

We'll cover the following...
Press + to interact
package main
import (
"fmt"
)
// aliasing type
type Celsius float32
type Fahrenheit float32
// Function to convert celsius to fahrenheit
func toFahrenheit(t Celsius) Fahrenheit {
return Fahrenheit((t*9/5 )+ 32)
}
func main() {
var tempCelsius Celsius = 100
tempFahr := toFahrenheit(tempCelsius) // function call
fmt.Printf("%f ˚C is equal to %f ˚F",tempCelsius,tempFahr)
}

We aliased the types of the temperature, i.e., float32 to Celsius and Fahrenheit. At line 7, we alias the type float 32 by giving the name Celsius. We need another type called Fahrenheit, so we alias the type ...