VB.Net Program to Create a Simple Calculator Using ‘Select Case’

You are currently viewing VB.Net Program to Create a Simple Calculator Using ‘Select Case’

VB.Net program to create a simple calculator using ‘select case’

'VB.Net program to create the simple calculator 
'using "select case".

Module Module1

    Sub Main()
        Dim choice As Integer

        Dim num1 As Integer = 0
        Dim num2 As Integer = 0
        Dim result As Integer = 0


        Console.WriteLine("############################")
        Console.WriteLine("     1: Addition")
        Console.WriteLine("     2: Subtraction")
        Console.WriteLine("     3: Multiplication")
        Console.WriteLine("     4: Division")
        Console.WriteLine("############################")

        Console.Write("Enter choice: ")
        choice = Integer.Parse(Console.ReadLine())

        Console.Write("Enter number1: ")
        num1 = Integer.Parse(Console.ReadLine())

        Console.Write("Enter number2: ")
        num2 = Integer.Parse(Console.ReadLine())

        Select Case choice
            Case 1
                result = num1 + num2
            Case 2
                result = num1 - num2
            Case 3
                result = num1 * num2
            Case 3
                result = num1 / num2
            Case Else
                Console.WriteLine("Invalid choice")
        End Select

        Console.WriteLine("Result:  {0}", result)
    End Sub
    
End Module

Output

############################
     1: Addition
     2: Subtraction
     3: Multiplication
     4: Division
############################
Enter choice: 3
Enter number1: 3
Enter number2: 6
Result:  18
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply