Struggle for working conditions in nurseries
I was doing Baa Baa Black Sheep in VB and got stuck in the final part of my program. I'm trying to get the program to indicate if the user is entering 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
source to share
You must use operators AndAlso
to compare your values.
If FirstBag = "master" AndAlso SecondBag = "dame" AndAlso ThirdBag = "little girl" Then
You can do this with normal operators And
, but it AndAlso
supports short-circuiting.
Edit: Short-circuiting is a programming construct that allows you to skip evaluating parts of a multi-part conditional expression if the earlier part of the expression makes validating the rest of the statement meaningless.
Example: a == b AndAlso c == d
won't try to evaluate c == d
if a == b
returnsfalse
source to share