while (asteriskWord != hangCharacters && score < 5)
{
while ( letter != ) //This is where I want to test for A-Z a-z
{
Console.WriteLine("Enter a letter please");
letter = Convert.ToChar(Console.ReadLine());
}
}
After the first while-loop
I want to be able to place the input inside of a while loop that breaks if the value is = letters A-Z or a-z.
This is so that if the user enters the wrong information, the loop will continue
to ask for the information.
Thank you for your time and consideration. Also I tried doing letter != 'A' && letter != 'a'...... and so on, but it didn't work for some reason.
Well the simplest way would be to just use comparisons. If you definitely want to do it in a single expression, Glorfindel's answer is appropriate. However, all those brackets and the negation makes me nervous of the readability. I'd break it into a separate method:
while (!IsValidLetter(letter))
{
...
}
...
private static bool IsValidLetter(char letter)
{
return (letter >= 'a' && letter <= 'z') ||
(letter >= 'A' && letter <= 'Z');
}
Whichever you find more readable - the latter is easier to modify later, of course, if you end up with more complicated requirements.
See more on this question at Stackoverflow