Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created February 19, 2013 18:22
Show Gist options
  • Save jpetto/4988451 to your computer and use it in GitHub Desktop.
Save jpetto/4988451 to your computer and use it in GitHub Desktop.
Simple guessing game
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