Skip to content

Instantly share code, notes, and snippets.

@matthewpwatkins
Created December 14, 2017 01:18
Show Gist options
  • Save matthewpwatkins/c7e99068d867dbffd794fdd4420c9acb to your computer and use it in GitHub Desktop.
Save matthewpwatkins/c7e99068d867dbffd794fdd4420c9acb to your computer and use it in GitHub Desktop.
Guessinator
using System;
namespace Guessinator
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Hello world! Would you like to play a guessing game?");
var input = Console.ReadLine().ToLowerInvariant();
if (input.Contains("yes"))
{
Console.WriteLine("OK, We'll play a game");
var randomNumber = GuessNumber(1, 1000);
Console.WriteLine("Guess a number:");
var userGuess = int.Parse(Console.ReadLine());
while (userGuess != randomNumber)
{
if (userGuess > randomNumber)
{
Console.WriteLine($"You stink. It's lower than {userGuess}.");
}
else
{
Console.WriteLine($"You stink. It's higher than {userGuess}.");
}
userGuess = int.Parse(Console.ReadLine());
}
Console.WriteLine("You won, but you still stink.");
}
else
{
Console.WriteLine("You stink.");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
static int GuessNumber(int lowerNumber, int higherNumber) => new Random().Next(lowerNumber, higherNumber);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment