Programming Fundamentals/Conditions/VB.NET: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Creating |
(No difference)
|
Revision as of 22:46, 3 February 2017
conditions.vb
' This program asks the user to select Fahrenheit or Celsius conversion
' and input a given temperature. Then the program converts the given
' temperature and displays the result.
Imports System
Public Module MyProgram
Sub Main
Dim Choice As String
Console.WriteLine("Enter F to convert to Fahrenheit or C to convert to Celsius:")
Choice = Console.ReadLine()
If Choice = "C" Or Choice = "c" Then
ToCelsius()
ElseIf Choice = "F" Or Choice = "f" Then
ToFahrenheit()
Else
Console.WriteLine("You must enter C to convert to Celsius or F to convert to Fahrenheit!")
End If
End Sub
Private Sub ToCelsius()
Dim F As Double
Dim C As Double
Console.WriteLine("Enter Fahrenheit temperature:")
F = Convert.ToDouble(Console.ReadLine())
C = (F - 32) * 5 / 9
Console.WriteLine(F & "° Fahrenheit is " & C & "° Celsius")
End Sub
Private Sub ToFahrenheit()
Dim C As Double
Dim F As Double
Console.WriteLine("Enter Celsius temperature:")
C = Convert.ToDouble(Console.ReadLine())
F = C * 9 / 5 + 32
Console.WriteLine(C & "° Celsius is " & F & "° Fahrenheit")
End Sub
End Module
Try It
Copy and paste the code above into one of the following free online development environments or use your own VB.NET compiler / interpreter / IDE.