Created
February 19, 2013 18:22
-
-
Save jpetto/4988451 to your computer and use it in GitHub Desktop.
Simple guessing game
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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleGuessingGame1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// declare and initialize a random number generator | |
Random rnd = new Random(); | |
// declare and initialize a random number between 1 and 10 | |
int myrand = rnd.Next(10) + 1; | |
Greeting(myrand); | |
int guess = int.Parse(Console.ReadLine()); | |
Respond(guess, myrand); | |
Console.ReadKey(); | |
} | |
static void Greeting(int myrand) | |
{ | |
// ask the user to guess the number | |
Console.WriteLine("Guess the secret number!"); | |
// give them a hint (for testing) | |
Console.WriteLine("(Hint: the number is " + myrand + ")"); | |
} | |
static void Respond(int guess, int myrand) | |
{ | |
if (guess == myrand) | |
{ | |
Console.WriteLine("You got it!"); | |
} | |
else | |
{ | |
Console.WriteLine("Nope!"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment