Skip to content

Instantly share code, notes, and snippets.

@prajaybasu
Last active September 30, 2018 02:06
Show Gist options
  • Save prajaybasu/b84370c1a39622e3016dbbfd9103cdad to your computer and use it in GitHub Desktop.
Save prajaybasu/b84370c1a39622e3016dbbfd9103cdad to your computer and use it in GitHub Desktop.
GuessTheNumber
using System;
namespace GuessTheNumber
{
class Program
{
const int MinRandomValue = 0;
const int MaxRandomValue = 25;
static readonly int RandomNumber = new Random().Next(MinRandomValue, MaxRandomValue + 1);
static void Main(string[] args)
{
Console.WriteLine($"Welcome to Guess the Number! ( {RandomNumber} )");
Console.WriteLine($"Please guess a number {MinRandomValue} - {MaxRandomValue}:");
var tries = 1;
while (true)
{
if (int.TryParse(Console.ReadLine(), out int playerGuess) == false)
{
Console.WriteLine("Invalid Input. Please try again:");
continue;
}
if (playerGuess == RandomNumber)
{
if (tries == 1)
{
Console.WriteLine("Awesome! You got it on the first try!");
}
else
{
Console.WriteLine($"You got it with {tries} tries!");
}
break;
}
else if (playerGuess < RandomNumber)
{
Console.WriteLine("Higher!");
}
else if (playerGuess > RandomNumber)
{
Console.WriteLine("Lower!");
}
tries++;
}
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment