我只是在学习 Visual Basic。我试着做一个计算器,但我想要它,所以如果你有任何不在 if 语句中的东西,它会说“对不起”并返回到开头。这是代码:
Module Module1
Sub Main()
Dim num1 As Integer
Dim num2 As Integer
Dim op As String
Console.WriteLine("Calculator")
Console.WriteLine(" ")
Console.WriteLine("Valid Operators :")
Console.WriteLine("+(Addition), -(Subtraction), *(Multiplication) & /(Division)")
Console.WriteLine(" ")
Console.WriteLine("Enter Number 1 :")
num1 = Console.ReadLine()
Console.WriteLine(" ")
Console.WriteLine("Enter Number 2 :")
num2 = Console.ReadLine()
Console.WriteLine(" ")
Console.WriteLine("Enter Operator :")
op = Console.ReadLine()
If op = "+" Then
Console.WriteLine(" ")
Console.WriteLine("Answer :")
Console.WriteLine(num1 + num2)
Console.WriteLine(" ")
Console.WriteLine("Press <Enter> To Exit")
Console.ReadLine()
End If
If op = "-" Then
Console.WriteLine(" ")
Console.WriteLine("Answer :")
Console.WriteLine(num1 - num2)
Console.WriteLine(" ")
Console.WriteLine("Press <Enter> To Exit")
Console.ReadLine()
End If
If op = "*" Then
Console.WriteLine(" ")
Console.WriteLine("Answer :")
Console.WriteLine(num1 * num2)
Console.WriteLine(" ")
Console.WriteLine("Press <Enter> To Exit")
Console.ReadLine()
End If
If op = "/" Then
Console.WriteLine(" ")
Console.WriteLine("Answer :")
Console.WriteLine(num1 / num2)
Console.WriteLine(" ")
Console.WriteLine("Press <Enter> To Exit")
Console.ReadLine()
End If
If op = Nothing Then
Console.WriteLine(" ")
Console.WriteLine("You have not entered a valid operator.")
Console.WriteLine(" ")
Console.WriteLine("Press <Enter> To Exit")
Console.ReadLine()
End If
End Sub
End Module
任何人都可以帮忙吗?