6 Program in Visual Basic on Console Based Calculator Using Select Case Statement.

Code:

Module Module1

    Dim a, num1, num2, result As Integer
    Dim b As Boolean

    Sub Main()

        Console.WriteLine()
        Console.WriteLine(" Calculator ")
        b = True

        Console.WriteLine("Operations Available : ")
        Console.WriteLine("1 Addition")
        Console.WriteLine("2 Substraction")
        Console.WriteLine("3 Multiplication ")
        Console.WriteLine("4 Division")

        Console.WriteLine("Enter your Choice : ")
        a = Console.ReadLine()

        Console.WriteLine("Enter any two number: ")
        num1 = Console.ReadLine()
        num2 = Console.ReadLine()

        Select Case a
            Case 1
                result = num1 + num2
            Case 2
                result = num1 - num2
            Case 3
                result = num1 * num2
            Case 4
                result = num1 / num2

            Case Else
                Console.WriteLine(" Invalid Choice ")
                b = False
        End Select

        If b Then
            Console.WriteLine("Result=" & result)
        End If

        Console.ReadKey()
    End Sub

End Module



Output:


Previous
Next Post »