T
Trev
Hi,
I'm learning C# and trying to write the program below, everything
works fine until the last section:
Console.Write("Would you like to play again y/n: ");
again = Console.ReadLine();
if (again.ToLower() == "y")
{
????
}
else
Console.WriteLine("GoodBye");
How do I loop the program to start again, I tried copying the whole
program into the if statement but this doesn't work any ideas?
static void Main(string[] args)
{
Random generator = new Random();
int RandomNumber = generator.Next(1,100);
int score = 1;
int Guess = 0;
string again;
while (Guess != RandomNumber)
{
Console.Write("Guess a number from 1 to 100: ");
Guess = Convert.ToInt32(Console.ReadLine());
if (Guess == RandomNumber)
Console.WriteLine("Your Correct. It took you " + score + "
Tries");
else if( Guess > RandomNumber)
Console.WriteLine("To High");
else Console.WriteLine("To Low");
score++;
}
Console.Write("Would you like to play again y/n: ");
again = Console.ReadLine();
if (again.ToLower() == "y")
{
????
}
else
Console.WriteLine("GoodBye");
}
}
}
I'm learning C# and trying to write the program below, everything
works fine until the last section:
Console.Write("Would you like to play again y/n: ");
again = Console.ReadLine();
if (again.ToLower() == "y")
{
????
}
else
Console.WriteLine("GoodBye");
How do I loop the program to start again, I tried copying the whole
program into the if statement but this doesn't work any ideas?
static void Main(string[] args)
{
Random generator = new Random();
int RandomNumber = generator.Next(1,100);
int score = 1;
int Guess = 0;
string again;
while (Guess != RandomNumber)
{
Console.Write("Guess a number from 1 to 100: ");
Guess = Convert.ToInt32(Console.ReadLine());
if (Guess == RandomNumber)
Console.WriteLine("Your Correct. It took you " + score + "
Tries");
else if( Guess > RandomNumber)
Console.WriteLine("To High");
else Console.WriteLine("To Low");
score++;
}
Console.Write("Would you like to play again y/n: ");
again = Console.ReadLine();
if (again.ToLower() == "y")
{
????
}
else
Console.WriteLine("GoodBye");
}
}
}