Created
December 14, 2017 01:18
-
-
Save matthewpwatkins/c7e99068d867dbffd794fdd4420c9acb to your computer and use it in GitHub Desktop.
Guessinator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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