Lena has created a very simple Go program that takes as input the temperature in Celsius degrees and implements a method DisplayAllTemps() on the non-struct Temperature type that outputs both the input temperature (in Celsius) and also the converted values in Fahrenheit and Kelvin degrees.
When she tried to execute the program, she got a compiler error in the DisplayAllTemps() method declaration. Can you help Lena write the correct method declaration she should use in her program?
Below is the code she has written so far:
package main
import "fmt"
type Temperature float64
func (t ?) ?() { // The correct 'DisplayAllTemps() method declaration goes here
f := (t * 9 / 5) + 32
c := t
k := t + 273.15
fmt.Printf("\n\nTemperature in Celsius: %.2f°C\n", c)
fmt.Printf("Temperature in Fahrenheit: %.2f°F\n", f)
fmt.Printf("Temperature in Kelvin: %.2f K", k)
}
func main() {
var t Temperature
fmt.Printf("Please enter the temperature in Celsius: ")
fmt.Scanln(&t)
t.DisplayAllTemps()
}
Take notice that the method declaration you enter below should have the complete syntax, including func at the beginning:
func (t ?) ?()