gpt4 book ai didi

vb.net - 努力使童谣条件发挥作用

转载 作者:行者123 更新时间:2023-12-01 14:02:51 25 4
gpt4 key购买 nike

我一直在用 VB 制作 Baa Baa Black Sheep,但在我的程序的最后一点停滞不前。我试图让程序说明用户是否为拥有包的人输入了正确的信息,但它似乎没有注册最后一部分。非常感谢任何帮助!

Module Module1

Sub Main()
Dim WoolAnswer As String = ""
Dim BagNumber As Integer = 0
Dim FirstBag As String = ""
Dim SecondBag As String = ""
Dim ThirdBag As String = ""

Console.WriteLine("Do you have any wool?")
WoolAnswer = Console.ReadLine

If WoolAnswer = "yes" Then
Console.WriteLine("How many bags do you have?")
BagNumber = Console.ReadLine

If BagNumber = 3 Then
Console.WriteLine("Who is the first bag for?")
FirstBag = Console.ReadLine()

Console.WriteLine("Who is the second bag for?")
SecondBag = Console.ReadLine

Console.WriteLine("Who is the third bag for?")
ThirdBag = Console.ReadLine
Else
Console.WriteLine("That is not the correct amount of bags.")
End If

Else
Console.WriteLine("You have no wool.")
End If

**If (FirstBag = "master" & SecondBag = "dame" & ThirdBag = "little girl") Then
Console.WriteLine("You really know your nursery rhymes!")
End If**
**This is the part that doesn't work**

Console.ReadLine()
End Sub

End Module

最佳答案

您应该使用 AndAlso 运算符来比较您的值。

如果 FirstBag = "master"AndAlso SecondBag = "dame"AndAlso ThirdBag = "little girl"Then

您可以使用普通的 And 运算符来完成,但 AndAlso 支持短路。

编辑:短路是一种编程结构,如果语句的较早部分使检查语句的其余部分毫无意义,它允许您跳过对多部分条件语句的部分的评估。

示例:如果 a == b 返回,a == b AndAlso c == d 将不会尝试计算 c == d 错误

关于vb.net - 努力使童谣条件发挥作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26240192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com