2

This is my very rudimentary guessing game. The answer is "luigi", but if I type "Luigi", it doesn't register as a valid answer because my secretWord (luigi) is not in the same caps. how do I get around this in c#?

These are my variables:

string secretWord1 = "luigi";

string guess = "";

int guessLimit = 0;

bool outOfGuesses = false;

int guessesLeft = 3;

This my guessing game:

        Console.WriteLine("He is a video game character");
        while (guess != secretWord1 && !outOfGuesses)
        {
            if (guessesLeft > guessLimit)
            {
                Console.Write("Enter guess: ");
                guess = Console.ReadLine();
                guessesLeft--;
                if (guessesLeft == 2 && guess != secretWord1)
                {
                    Console.WriteLine("He is a character in a Nintendo game");
                }
                if (guessesLeft == 1 && guess != secretWord1)
                {
                    Console.WriteLine("He is a character from the Mario Bros. games");
                }
                Console.WriteLine(guessesLeft);
            }
            else
            {
                outOfGuesses = true;
            }
        }
        if (outOfGuesses)
        {
            Console.WriteLine("You Lose");
            Console.ReadLine();
        }
        else
        {
            Console.WriteLine("You Win!");
            Console.ReadLine();
        }
2
  • 1
    Does this answer your question? How can I do a case insensitive string comparison? Commented May 8, 2020 at 3:06
  • To make sure all cases, you can change the while line to: while (guess.ToLower() != secretWord1.ToLower() && !outOfGuesses) Commented May 8, 2020 at 3:08

2 Answers 2

2

Change the 7th line to this

guess = Console.ReadLine().toLower();

Please see

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

Comments

1

Use the .Equals String Comparison

!guess.Equals(secretWord1, StringComparison.InvariantCultureIgnoreCase)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.