I'm trying to make this loop work so it will keep asking for a number until the user enters 999. However with this version of code, it won't build saying I can't declare num within the loop becuase I'm giving it different meaning in this scope.
The try and catch are used because of my assignment rules for this piece of code.
int num;
while (num != 999)
{
Console.WriteLine("Enter a number between 0 and 99");
string input = Console.ReadLine();
try
{
int num = Convert.ToInt32(input);
Console.WriteLine("This is element number " + num + " : " + randNums[num]);
}
catch
{
Console.WriteLine("Data inputted is not between 0 and 99");
}
}
Console.WriteLine("You chose the secret value, well done!");
intfrom in front of the secondnumnumvariable should be initialized to some value before it can be used. Even if that is not the problem, I think the compiler will complain