jeudi 22 septembre 2016

Guessing Game in C# where User selects Max value

I have been tasked in my class to create a random number generating guessing game using c# and do/while, if/else loops. This task seems easy enough; however, I am running into problems because I am supposed to start the game by prompting the user to "Enter a max value you want to guess from". I cannot get my program to work properly, as every time I run it, no matter what value I enter it says to "select a value between 1 and 0"

I have attached my exe.

Thanks in advance !!

        Random generator = new Random();
        bool truth = true;
        int MaxRange = Convert.ToInt32(truth); ;
        int userguess = 0;
        int outputnumber = generator.Next(MaxRange);

        do
        {
            Console.WriteLine(" Enter a max number you want to guess from!", MaxRange);
            Console.ReadLine();

            Console.WriteLine("please make a guess between 1 and {0}", outputnumber);

            if (userguess != outputnumber)
            {
                userguess = Convert.ToInt32(Console.Read());

                if (userguess < outputnumber)
                {
                    Console.WriteLine("That is not correct, Guess again");
                    Console.ReadLine();

                }
                if(userguess > outputnumber)
                {

                    Console.WriteLine("That is not correct, Guess again");
                    Console.ReadLine();
                }

                else if (userguess == outputnumber)
                {

 console.writeline("That is correct, the number is {0}, outputnumber);

                }
            }

        } while (truth == false);






        }
    }
}




Aucun commentaire:

Enregistrer un commentaire