I'm trying to make a program that generates a random number between 1-100, let's the user guess till they get the correct number, tells the use if they guessed too high/low and also let's them know if they guess correctly and if so, tell's them how many guesses it took. But I want to make it more complicated by letting the user know when they are close to the number.
This is how my code looks so far:
using System.Diagnostics.CodeAnalysis;
Random random = new Random();
bool playAgain = true;
int min = 1;
int max = 101;
int guess;
int number;
int guesses;
while (playAgain)
{
guess = 0;
guesses = 0;
number = random.Next(min, max);
while (guess != number)
{
Console.WriteLine("Try to guess the randomly generated number " + min + "-" + max + ":");
guess = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Guess: " + guess);
if (guess < number)
{
Console.WriteLine("Number " + guess + " is too low...");
}
else if (guess > number)
{
Console.WriteLine("Number " + guess + " is too high!");
}
guesses++;
}
Console.WriteLine("You won! Good job!");
Console.WriteLine("Total guesses; " + guesses);
}