secret
Created

[1/2/2013] Challenge #115 [Easy] Guess-that-number game! - BEGINNER SOLUTION

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
class Program
{
static void Main(string[] args)
{
Game();
Console.ReadLine();
}
static void Game()
{
Random random = new Random();
int Random_Number = random.Next(0, 101);
B:
Console.WriteLine("Welcome to guess-that-numbers game! I have already picked a number in [1, 100]. Please make a guess. Type 'exit' to quit.");
string String_Answer = Console.ReadLine();
if (String_Answer.ToLower() == "exit")
Environment.Exit(0);
int Answer = 0;
int.TryParse(String_Answer, out Answer);
if (Answer < Random_Number)
{
Console.Clear();
Console.WriteLine("Wrong. That number is below my number. Please Try Again.");
goto B;
}
else if (Answer > Random_Number)
{
Console.Clear();
Console.WriteLine("Wrong. That number is above my number. Please Try Again");
goto B;
}
else if (Answer == Random_Number)
{
Console.Clear();
Console.WriteLine("Correct! That is my number, you win!");
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.