Now that we’ve learned about the basics of variables and arithmetic operators, let’s write a program!
The mad scientist Kelvin has mastered predicting the weather in his mountain-side meteorology lab.
Recently, Kelvin began publishing his weather forecasts on his website, however, there’s a problem: All of his forecasts describe the temperature in Fahrenheit degrees.
Let’s convert a temperature from Fahrenheit (°F) to Celsius (°C).
The formula is the following:
Instructions
First, search for the current temperature of New York City in Fahrenheit.
Declare a Double
variable named tempf
and initialize it with the temperature.
Declare another Double
variable named tempc
.
Convert the temperature to Celsius using the formula provided.
Store the result in tempc
.
Display the result using string interpolation. Output exactly like so:
The temp is [tempc] degrees Celsius.