From 73d53ef29cf1c5a699e23c7d0bdfdc009e68b5e6 Mon Sep 17 00:00:00 2001 From: kemery Date: Wed, 22 May 2019 15:03:30 -0400 Subject: [PATCH] Completed working version of numbers game --- NumberGuessingGame/Program.cs | 60 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/NumberGuessingGame/Program.cs b/NumberGuessingGame/Program.cs index 80a2898..d85acab 100644 --- a/NumberGuessingGame/Program.cs +++ b/NumberGuessingGame/Program.cs @@ -1,42 +1,42 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace NumberGuessingGame +namespace KimGuessingGame { class Program { - static void Main(string[] args) + static int GenerateRandomNumber(int min, int max) { - int min = 1; - int max = 20; - Console.WriteLine("I'm thinking of a number between {0} and {1}. Can you guess it in 3 tries?", min, max); - - // TODO: Create a console app that picks a random number and then gives the user 3 chances to guess it. - - - //TODO: Use our GenerateRandomNumber() method to generate the number and store it in a variable. - - //TODO: while loop for three guesses - //ask the user to guess a number between 1 and 20 (use console.writeline) - //store the users answer in a variable - //use an if else conditional to determine if their guess is equal to yours - //if equal win, give them a win message - - - // With each incorrect answer tell the user if the correct answer is higher or lower. - // At the end ask if they want to play again or end. - - Console.ReadKey(); - + Random rnd = new Random(); + return rnd.Next(min, max); } - static int GenerateRandomNumber(int min, int max) + static void Main(string[] args) { - Random rnd = new Random(); - return rnd.Next(min,max); + int min = 1; + int max = 20; + int returnValue = GenerateRandomNumber(min, max); + int Guess = 0; + int numGuesses = 0; + + Console.WriteLine("I am thinking of a number between {0}-{1}. Can you guess what it is?", min, max); + + while (Guess != returnValue) + { + Guess = Convert.ToInt32(Console.ReadLine()); + if (Guess < returnValue) + { + Console.WriteLine("No, the number I am thinking of is higher than " + Guess + " . Can you guess what it is?"); + } + if (Guess > returnValue) + { + Console.WriteLine("No, the number I am thinking of is lower than " + Guess + " . Can you guess what it is"); + } + } + numGuesses++; + Console.WriteLine("Well done! The answer was " + returnValue + ".\nYou took " + numGuesses + " guesses."); } } + } + +