Visual Basic控制台应用程序

3
我正在制作一个计算机科学的控制台应用程序。如果两个数字相同,它会显示一条消息,如果它们不同,则会显示另一条消息。以下是我的代码:
Module Module1

Sub Main()
 Dim NumberOne As Integer
 Dim NumberTwo As Integer
 Console.WriteLine("Enter your first number and then press the enter key")
 NumberOne = Console.ReadLine
 Console.WriteLine("Now enter your second number and press the enter key")
 NumberTwo = Console.ReadLine
 If NumberOne = NumberTwo Then
 Console.WriteLine("You entered the same two numbers!")
 Console.ReadLine()
 End If
 If NumberOne <= NumberTwo Then
 Console.WriteLine("You entered two different numbers")
 Console.ReadLine()
 End If
 End Sub
End Module

这段代码运行良好,但问题在于如果您输入两个相同的数字,它会提示您已经输入了相同的数字,但是当您按下回车键时,它会显示另一条消息,说您输入了两个不同的数字。

有人知道我如何让它只执行其中一个操作吗?

谢谢,

Jake


1
如果 NumberOne <= NumberTwo,那么 VB.NET 中的“不等于”运算符是 <> - Laoujin
1个回答

5
请修改您的代码:
 If NumberOne = NumberTwo Then
 Console.WriteLine("You entered the same two numbers!")
 Console.ReadLine()
 Else
 Console.WriteLine("You entered two different numbers")
 Console.ReadLine()
 End If

希望这可以帮助你!

太棒了 - 那个小的Else语句让它工作了!谢谢你! - Jake Andrew
需要15个声望才能投票:(不过我已经标记为答案了:) - Jake Andrew
没问题。谢谢你的努力。 - Vijay Joseph

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接