目前,仅当用户输入与迭代中的指定字母匹配时,程序才会显示字母。
我想做的是显示一个字母,尽管用户正在进行什么迭代。如果用户输入"P"在第一次迭代中,我希望程序显示所有P" in happy.
谢谢!
我想做的是显示一个字母,尽管用户正在进行什么迭代。如果用户输入"P"在第一次迭代中,我希望程序显示所有P" in happy.
谢谢!
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();
}
}
}