I've been making Baa Baa Black Sheep in VB and have gotten stuck on the final bit of my program. Im trying to make the program state whether the user has entered the correct information for the people who own the bags, but it doesn't seem to register the final part. Any help is greatly appreciated!
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
You should use the AndAlso operators to compare your values.
If FirstBag = "master" AndAlso SecondBag = "dame" AndAlso ThirdBag = "little girl" Then
You could do it with plain And operators, but AndAlso supports short-circuiting.
Edit: Short-circuiting is a programming construct which allows you to skip over evaluation of portions of a multi part conditional statement if an earlier portion of the statement renders checking the rest of the statement pointless.
Example: a == b AndAlso c == d will not attempt to evaluate c == d if a == b returns false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With