vendredi 24 août 2018

C# Random number keeps changing its numbers

Hello so I was trying to create this "game" where the computer guesses a number between 1 to 100, and you have to input the number you guess, and it will say its guessed number is lower than what the user said or higher, now the problem here is that each time the user inputs a number, the random number changes, i have tried many things, but i never got a result. Take a look at my code.

Random rnd = new Random();
        int cmptr = rnd.Next(1, 101);       
        Console.WriteLine("Computer: I chosen a number between 1 to 100, guess it.");
        Console.WriteLine("Chosen number is displayed just for testing purposes: " + cmptr + ")"); // for test purposes only
        int usr = (Convert.ToInt32(Console.ReadLine()));
        while (usr != cmptr)
        {
            if (usr < cmptr)
            {
                Console.WriteLine("Computer: Mine is Greater!");
            }
            else if (usr > cmptr)
            {
                Console.WriteLine("Computer: Mine is Lower!");
            }

            usr = Convert.ToInt32(Console.ReadLine());
        }

        Console.WriteLine("Computer: Congrats you beat me!");




Aucun commentaire:

Enregistrer un commentaire