Random Generator Questions

c#

Solution

The upper limit for the `Next` method is exclusive, so you want to use 11 rather than 10 for that:

randomNumber = ranNumberGenerator.Next(min, max + 1);

You are ignoring the input from the user. Capture that in a string:

string input = Console.ReadLine();

Then parse the input to a number:

int number = Int32.Parse(input);

Now you can compare that number to the random number.

If you want to handle incorrect input from the user in a more user friendly way than crashing, you would use `TryParse` to attempt to parse the number.

Problem

How do i make a application that will produce a random number between 1-10 and then ask the user to guess that number, and if that number is matching the random number tell them if they got it right! I'm a student, like super new and was out of class for a few days because of surgery and i can not figure this out for the life of me! This is what i've come up with for the problem. ``` namespace GuessingGame { class Program { static void Main(string[] args) { int min = 1; int max = 10; Random ranNumberGenerator = new Random(); int randomNumber; randomNumber = ranNumberGenerator.Next(min, max); Console.WriteLine("Guess a random number between 1 and 10."); Console.ReadLine(); if (randomNumber == randomNumber) Console.WriteLine("You got it!"); else Console.WriteLine("Sorry, try again!"); } } } ```

Original source