Below you will see a Go program that converts the input temperature from Fahrenheit to Celsius and vice-versa:
package main
import "fmt"
func main() {
var temperature float64
var unit string
fmt.Scanln(&temperature, &unit)
if unit == "F" {
temperature = ... // code to transform from "F" to "C" goes here
fmt.Printf("%.2f C", temperature)
}
if unit == "C" {
temperature = ... // code to transform from "C" to "F" goes here
fmt.Printf("%.2f F", temperature)
}
}
- The formula to convert from Fahrenheit to Celsius is:
- The formula to convert from Celsius to Fahrenheit is:
Your task is to use functional decomposition and create three functions:
-
fahrenheitToCelsius()which converts thetemperaturefrom Fahrenheit to Celsius and then prints the converted value; -
celsiusToFahrenheit()which converts thetemperaturefrom Celsius to Fahrenheit and then prints the converted value; convertTemperature()that takes as arguments thetemperatureand theunitand then calls the correct temperature conversion function using anifstatement based on theunit.
Note that for this task, you must not modify or delete any code within the
main() function!