私は異なる動物のための分類プログラムを作ろうとしています。以下は私のコードです(例として動物は1つだけです)。このプログラムは、各質問に対する回答のユーザー入力を受け取り、配列(answerList)に追加することを目的としています。この例では、answerList
(すべてのユーザー入力を含む配列)がHorse
配列に等しい場合、ユーザーにはその動物が馬であることが伝えられます。2つの文字列配列が等しいかどうかを確認するにはどうすればよいですか?
ただし、コードの最後のfour lines
は機能しません。それは最終的な出力を生成しません。私の下のコードを動作させるにはどうしてですか?
Sub Main()
Dim aAquatic, aInsect, aTentacles, aBird, aFlippers, aFly, aHoney, aLegs, aFeline, aStripes, aDomestic, aMilk, aWool, aSnout
Dim Horse = {“n”, “n”, “n”, “n”, “n,”, "n", “n”, “n”, “n”, “n”, “n”, “n”, “n”, “n”}
Dim animalArray = {Horse, Cow, Sheep, Pig, Dog, Cat, Lion, Tiger, Dolphin, Seal, Penguin, Ostrich, Sparrow, Bee, Wasp, Termite, Octopus}
Console.WriteLine("Welcome to the classification. Choose one of these animals and I will attempt to guess it: horse, cow, sheep, pig, dog, cat, lion, tiger, dolphin, seal, penguin, ostrich, sparrow, bee, wasp, termite, octopus. Click enter to continue.")
Console.ReadLine()
Console.WriteLine("Is your animal aquatic? (y or n)")
aAquatic = CStr(Console.ReadLine())
If aAquatic = "y" Then
answerList.Add("y")
ElseIf aAquatic = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Is your animal an insect? (y or n)")
aInsect = CStr(Console.ReadLine())
If aInsect = "y" Then
answerList.Add("y")
ElseIf aInsect = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Does your animal have tentacles? (y or n)")
aTentacles = CStr(Console.ReadLine())
If aTentacles = "y" Then
answerList.Add("y")
ElseIf aTentacles = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Is your animal a bird? (y or n)")
aBird = CStr(Console.ReadLine())
If aBird = "y" Then
answerList.Add("y")
ElseIf aBird = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Does your animal have flippers? (y or n)")
aFlippers = CStr(Console.ReadLine())
If aFlippers = "y" Then
answerList.Add("y")
ElseIf aFlippers = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Can your animal fly? (y or n)")
aFly = CStr(Console.ReadLine())
If aFly = "y" Then
answerList.Add("y")
ElseIf aFly = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Can your animal make honey? (y or n)")
aHoney = CStr(Console.ReadLine())
If aHoney = "y" Then
answerList.Add("y")
ElseIf aHoney = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Does your animal have two legs? (y or n)")
aLegs = CStr(Console.ReadLine())
If aLegs = "y" Then
answerList.Add("y")
ElseIf aLegs = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Is your animal a feline? (y or n)")
aFeline = CStr(Console.ReadLine())
If aFeline = "y" Then
answerList.Add("y")
ElseIf aFeline = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Does your animal have stripes? (y or n)")
aStripes = CStr(Console.ReadLine())
If aStripes = "y" Then
answerList.Add("y")
ElseIf aStripes = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Is your animal a domestic pet? (y or n)")
aDomestic = CStr(Console.ReadLine())
If aDomestic = "y" Then
answerList.Add("y")
ElseIf aDomestic = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Does your animal produce milk we can drink? (y or n)")
aMilk = CStr(Console.ReadLine())
If aMilk = "y" Then
answerList.Add("y")
ElseIf aMilk = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Does your animal have wool? (y or n)")
aWool = CStr(Console.ReadLine())
If aWool = "y" Then
answerList.Add("y")
ElseIf aWool = "n" Then
answerList.Add("n")
End If
Console.WriteLine("Does your animal have a snout? (y or n)")
aSnout = CStr(Console.ReadLine())
If aSnout = "y" Then
answerList.Add("y")
ElseIf aSnout = "n" Then
answerList.Add("n")
End If
Console.ReadKey()
String.Join(", ", answerList)
String.Join(", ", Horse)
If answerList Is Horse Then
Console.WriteLine("Your animal is a horse.")
End If
私は今、解決策がありますので心配はありません(: – Lauren
)配列はIEnumerableなので、['Enumerable.SequenceEqual'](https ://msdn.microsoft.com/en-us/library/bb348567(v = vs.110).aspx)目的を確認するための文字列の作成を避けるために – Sehnsucht