I am trying to code a while loop, I am trying to have a user enter a number from 1 to 50 and display the numbers. What I have so far prints out a message if I am within 50 and prints another message if I am over 50 but I need it to continue if the user wants to enter another number but it just exits.
Below is what I have:
class Program
{
static void Main(string[] args)
{
const int from = 1;
const int to = 50;
int randomNumber = 50;
int enteredNumber;
Console.Write("The number is between 1 and 50.", from, to);
while (true)
{
Console.Write("Enter a number: ");
if (int.TryParse(Console.ReadLine(), out enteredNumber))
{
if (enteredNumber <= randomNumber)
{
Console.WriteLine("You entered a number between 1 & 50");
break;
}
else
{
if (enteredNumber > randomNumber)
{
Console.WriteLine("You didn't enter a number between 1 & 50.");
break;
}
else
{
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
}
}
}