0% found this document useful (0 votes)
44 views2 pages

Simple Calculator

The document describes a Visual Basic .NET simple calculator program that allows a user to choose an operator, enter two numbers, and see the result of the calculation. The program uses a loop to allow the user to perform multiple calculations. It displays menus to choose the operator and get the user input, performs the calculation based on the selected operator, and displays the result. It also handles errors for invalid operators or division by zero.

Uploaded by

hakdogzhahaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Simple Calculator

The document describes a Visual Basic .NET simple calculator program that allows a user to choose an operator, enter two numbers, and see the result of the calculation. The program uses a loop to allow the user to perform multiple calculations. It displays menus to choose the operator and get the user input, performs the calculation based on the selected operator, and displays the result. It also handles errors for invalid operators or division by zero.

Uploaded by

hakdogzhahaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Imports System

Module Module1
Sub Main(args As String())
While True
Console.Clear()

Dim num1, num2, result As Double


Dim operatorName As Char
Dim operatorSymbol As String = ""

Console.WriteLine(" --------------------------------")
Console.WriteLine(" || VB.NET SIMPLE CALCULATOR ||")
Console.WriteLine(" --------------------------------")

Console.WriteLine(" -----------------------------------")
Console.WriteLine(" || CHOOSE THE OPERATOR SYMBOL ||")
Console.WriteLine(" -----------------------------------")
Console.WriteLine(" -------------------------------")
Console.WriteLine(" || (A) ADDITION (+) ||")
Console.WriteLine(" -------------------------------")
Console.WriteLine(" || (S) SUBTRACTION (-) ||")
Console.WriteLine(" -------------------------------")
Console.WriteLine(" || (M) MULTIPLICATION (*) ||")
Console.WriteLine(" -------------------------------")
Console.WriteLine(" || (D) DIVISION (/) ||")
Console.WriteLine(" -------------------------------")
Console.WriteLine(" -------------------------------")

Console.WriteLine(" ----------------------------------------")
Console.Write(" || ENTER CHOICE OPERATOR SYMBOL: ")
operatorName = Char.ToUpper(Console.ReadKey().KeyChar)

Console.WriteLine(vbCrLf & "


----------------------------------------")
Console.Write(" || ENTER FIRST NUMBER: ")
num1 = Convert.ToDouble(Console.ReadLine())

Console.WriteLine(vbCrLf & "


----------------------------------------")
Console.Write(" || ENTER SECOND NUMBER: ")
num2 = Convert.ToDouble(Console.ReadLine())
Console.WriteLine(vbCrLf & "
----------------------------------------")

Console.WriteLine(" -------------------------")
Console.WriteLine(" || YOU ENTERED !!! ||")
Console.WriteLine(" -------------------------")
Console.WriteLine(" -----------------------------------------")
Console.WriteLine($" || FIRST NUMBER: {num1}
||")
Console.WriteLine(" -----------------------------------------")
Console.WriteLine($" || SECOND NUMBER: {num2}
||")
Console.WriteLine(" -----------------------------------------")

Select Case operatorName


Case "A"c
operatorSymbol = "+"
result = num1 + num2
Case "S"c
operatorSymbol = "-"
result = num1 - num2
Case "M"c
operatorSymbol = "*"
result = num1 * num2
Case "D"c
operatorSymbol = "/"
If num2 <> 0 Then
result = num1 / num2
Else
Console.WriteLine(" ------------------------------")
Console.WriteLine(" ------------------------------")
Console.WriteLine(" || ERROR DIVISION BY ZERO ||")
Console.WriteLine(" ------------------------------")
Console.WriteLine(" ------------------------------")
Return
End If
Case Else
Console.WriteLine(" ------------------------------")
Console.WriteLine(" ------------------------------")
Console.WriteLine(" || INVALID OPERATOR ||")
Console.WriteLine(" ------------------------------")
Console.WriteLine(" ------------------------------")
Return
End Select

Console.WriteLine(" -----------------------------------------")
Console.WriteLine($" || OPERATOR SYMBOL: {operatorSymbol}
||")
Console.WriteLine(" -----------------------------------------")
Console.WriteLine(" ------------------------------")
Console.WriteLine($" || RESULT: {result} ||")
Console.WriteLine(" ------------------------------")

Console.WriteLine("----------------------------------------------------------------
-")
Console.Write("|| DO YOU WANT TO PERFORM ANOTHER CALCULATION? (Y/N):
")
Dim input As String = Console.ReadLine().ToUpper()

Console.WriteLine("----------------------------------------------------------------
-")

If input <> "Y" Then


Console.WriteLine(" OKAY! GOODBYE. THANK
YOU:))")
Exit While
End If
End While
End Sub
End Module

You might also like