Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 66 / 68

Converting temperatures (Celsius and Fahrenheit)

This lesson covers converting between Celsius and Fahrenheit in VB.NET, as practice at turning a formula into code.

Celsius to Fahrenheit is c * 9 / 5 + 32; Fahrenheit to Celsius is (f - 32) * 5 / 9. Gathering a fixed formula into a function makes it easy to call again and again.

The sample code provides CelsiusToFahrenheit() and FahrenheitToCelsius(), each following its formula. You can watch 25 degrees Celsius become 77 Fahrenheit and 77 Fahrenheit become 25 Celsius.

A common early stumble is the order of operations. Get the sequence of multiplication, division, and addition wrong in c * 9 / 5 + 32 and the answer is wrong, so it pays to understand the formula before writing it.

In professional work, unit-conversion logic is needed in all sorts of places — weather applications, switching units in a system aimed at another country.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)