Loop through a string array, until the user input is the right answer.

cristoo

New member
Joined
May 3, 2019
Messages
2
Programming Experience
3-5
Hi, I apologize in advance for the ugliness of this code.
Hopefully someone can tell what I am trying to do- which is have a string of names, create a loop through the array of strings, have the console write "Wrong Answer..."
until the user input is the right answer. In this case 3 or Burt is right.
Thanks for any insight.


C#:
    string[] _Names = new string[4] { "Bill", "Ben", "Burt", "Bob" };

            string userInput = Console.ReadLine();

            foreach (string in _Names [1, 4])
            {

            while (userInput != _Names[3])
            {
            Console.WriteLine("Wrong answer. What was his name?");
            }

            Console.WriteLine("Yeah that was his name.");
            
            }
     }

}
 
To get repeated user input you must put that inside the loop.
 
Back
Top Bottom