# Hi I am Writing a calculator in Visual basics and there seems to be a Error occurring.

Dim a,b,c As Integer
Dim op As String
Console.Writeline("Calculater")
Console.Write ("Enter first number")
Console.write ("Enter second numbers")
Console.Write ("Enter Operator")
If op = "t" Then
c = a+b
ElseIf op = "-" Then
c = a-b
ElseIf op = "*" Then
c = a*b
ElseIf op = "/" Then
c = a/b
ElseIf
Console.WriteLine ("Invalid op")
End If
End Sub

answered Sep 10, 2023 by (140 points)
Dim a, b, c As Integer
Dim op As String

Console.WriteLine("Calculator")
Console.Write("Enter first number: ")

Console.Write("Enter second number: ")

Console.Write("Enter Operator: ")

If op = "+" Then
c = a + b
ElseIf op = "-" Then
c = a - b
ElseIf op = "*" Then
c = a * b
ElseIf op = "/" Then
If b = 0 Then
Console.WriteLine("Division by zero is not allowed")
Else
c = a / b
End If
Else
Console.WriteLine("Invalid operator")
End If

answered Nov 18, 2023 by (1,580 points)

Well, there are some syntax error with your code, can you try below code, I am sure it may fix the error you are getting.

Module Module1
Sub Main()
Dim a, b, c As Integer
Dim op As String

Console.WriteLine("Calculator")
Console.Write("Enter first number: ")

Console.Write("Enter second number: ")

Console.Write("Enter Operator: ")

If op = "+" Then ' Corrected the operator for addition
c = a + b
ElseIf op = "-" Then
c = a - b
ElseIf op = "*" Then
c = a * b
ElseIf op = "/" Then
If b <> 0 Then
c = a / b
Else
Console.WriteLine("Cannot divide by zero")
Exit Sub ' Exit the program if division by zero is attempted
End If
Else
Console.WriteLine("Invalid operator")
Exit Sub ' Exit the program for invalid operators
End If