hello, i downloaded microsoft visual c# 2008 a couple days ago and i've been trying to program stuff ever since, but i'm stuck and the sites i've visited don't really answer my question.
i've tried making a game guessing game, the console generates a random number when i start the program, which is great, but when it asks me if i want to play again and i say yes, the number repeats, how can i fix that?
here's the code.
Code:
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int input;
Random number = new Random();
int n = number.Next(100);
Start:
Console.WriteLine("Guess a number between 1 and 100");
input = int.Parse(Console.ReadLine());
if (input > n)
{
goto High;
}
else
if (input < n)
{
goto Low;
}
else
if (input == n)
{
goto Right;
}
High:
Console.WriteLine("Too High");
input = int.Parse(Console.ReadLine());
if (input > n)
{
goto High;
}
else
if (input < n)
{
goto Low;
}
else
if (input == n)
{
goto Right;
}
Low:
Console.WriteLine("Too Low");
input = int.Parse(Console.ReadLine());
if (input > n)
{
goto High;
}
else
if (input < n)
{
goto Low;
}
else
if (input == n)
{
goto Right;
}
Right:
Console.WriteLine("You guessed it!");
goto New;
New:
Console.WriteLine("would you like to play again? yes/no");
string answer = Console.ReadLine();
switch (answer.ToLower())
{
case "yes":
goto Start;
case "no":
goto End;
default:
Console.WriteLine("I don't understand, ");
goto New;
}
End:
return;
}
}
}
keep in mind i only have like 10 hours of experience, on my own, so i'm really noob, thx.