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

Here, we are going to learn how to create a simple calculator using 'select case' in VB.Net?
Submitted by Nidhi, on December 03, 2020 [Last updated : March 05, 2023]

Creating a simple calculator using 'select case' in VB.Net

Here, we will create a simple calculator using 'select case', here we perform addition, subtraction, multiplication, and division operation.

Program/Source Code:

The source code to create a simple calculator using "select case" is given below. The given program is compiled and executed successfully.

VB.Net code 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 . . .

Explanation:

In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created four variables choice, num1, num2, and result.

In the above program, we defined "select case" to perform the operation. Here we select 3rd case and perform the multiplication operation and print the result on the console screen.

VB.Net Basic Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.