0

This is a short function to check and make user write uppercase Y or N .I dont know why but even if the user enter upper case Y or N , still then the loop does not exit. Any help please?

 static char GetUpperCaseYN()
    {
        char choice='y';
        Console.WriteLine("Calculate Another? Y/N ");
        choice = char.Parse(Console.ReadLine());
        while (choice != 'Y' || choice != 'N')
        {
            Console.WriteLine("Invalid Response.Please enter Y or N");
            choice = char.Parse(Console.ReadLine());
        }
        return choice;
    }

1 Answer 1

4

Use && not ||; they can't both be false with one character :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.