Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions NumberGuessingGame/Program.cs
Original file line number Diff line number Diff line change
@@ -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.");
}
}

}