Exercise
Conversion
Objetive
Write a Visual Basic (VB.Net) program to convert Celsius degrees to Kelvin and Fahrenheit. The program will prompt the user to input the temperature in Celsius degrees, and then use the following conversion formulas:
Kelvin = Celsius + 273
Fahrenheit = Celsius x 1.8 + 32
The program will then display the equivalent temperature in both Kelvin and Fahrenheit units.
Code
' Import the System namespace to use Console class
Imports System
Public Class Program
' Main subroutine, entry point of the program
Public Shared Sub Main()
' Ask the user to input the temperature in Celsius
Console.Write("Enter the temperature in Celsius: ")
' Read the user's input and convert it to a double
Dim celsius As Double = Convert.ToDouble(Console.ReadLine())
' Convert Celsius to Kelvin using the formula
Dim kelvin As Double = celsius + 273
' Convert Celsius to Fahrenheit using the formula
Dim fahrenheit As Double = celsius * 1.8 + 32
' Display the equivalent temperature in Kelvin
Console.WriteLine("Temperature in Kelvin: " & kelvin)
' Display the equivalent temperature in Fahrenheit
Console.WriteLine("Temperature in Fahrenheit: " & fahrenheit)
End Sub
End Class