सामग्री पर जाएँ

कंप्यूटर प्रोग्रामिंग/कंडीशन/विजुअल बेसिक .नेट

विकिविश्वविद्यालय से
' 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
        IfElse()
        SelectCase()
    End Sub

    Private Sub IfElse()
        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 SelectCase()
        Dim Choice As String
        
        Console.WriteLine("Enter F to convert to Fahrenheit or C to convert to Celsius:")
        Choice = Console.ReadLine()
        Select Choice
            Case "C", "c"
                ToCelsius()
            Case "F", "f"
                ToFahrenheit()
            Case Else
                Console.WriteLine("You must enter C to convert to Celsius or F to convert to Fahrenheit!")
        End Select
    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

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।