At the moment the program will only reveal a letter if the users input matches the specified letter within the iteration.
What I would like to do is reveal a letter despite what iteration the user is on...e.g. if the user inputs "P" on the first iteration I want the program to reveal all the Ps" in happy.
Thanks!
What I would like to do is reveal a letter despite what iteration the user is on...e.g. if the user inputs "P" on the first iteration I want the program to reveal all the Ps" in happy.
Thanks!
C#:
{
string[] secret = { "h", "a", "p", "p", "y" };
string[] hidden = { "_", "_", "_", "_", "_" };
string letter = "";
Console.WriteLine("Welcome to guess a word game");
for (int i = 0; i < secret.Length; i++)
{
Console.WriteLine("Guess a letter: ");
letter = Console.ReadLine();
//revealing letters
if (secret[i] == letter)
{
hidden[i] = letter;
}
//displaying the word to the user after each guess
foreach (string k in hidden)
{
Console.Write(k.ToString());
}
Console.WriteLine();
}
Console.WriteLine();
// once broken out of the for loop it will inform the user if they have guessed the word correctly.
if(secret == hidden)
{
Console.WriteLine("You have guessed the correct word!");
}
else
{
Console.WriteLine("unfortunately you have not gussed the correct word");
}
Console.ReadLine();
}
}
}