ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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

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 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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.