lundi 13 juin 2016

c# console. Check if user input was already inputted

Im trying to make a user enter a char and check if they entered that char before. and if that happens ask him to enter another char that he hasn't used before. My knowledge is limited to if statements and loops so I would appreciate it if the solution is something that i can understand.

When i enter any letter e.g E it would throw it into the guessed array, if i enter E again, it throws into the guessed array again instead of asking the user to change the letter.

            string check= "";

            do
            {
                check = Console.ReadLine();

                if (check!="")
                {
                    wguess = char.ToUpper(Convert.ToChar(check));
                    for (int i = 0; i <= 25; i++)
                    {
                        if (wguess == guessed[i])
                        {
                            Console.Write(wguess);
                            Console.WriteLine(guessed[i]);
                            Console.WriteLine("Please choose a letter you haven't used yet.");
                        }
                        else
                        {
                            Console.Write(wguess);
                            Console.WriteLine(guessed[i]);
                            temp = wguess;
                            guessed[i] = wguess;
                            wguess = ' ';
                            same = false;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Please Enter a letter.");
                }
            } while (check=="");

Output1 Output2

Aucun commentaire:

Enregistrer un commentaire