Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string appName = "Number Guesser";
- string appVersion = "1.0.0";
- string appAuthor = "lazix";
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("{0}: Version {1} by {2}", appName, appVersion, appAuthor);
- Console.ResetColor();
- // Ask For User's Name
- Console.WriteLine("What is your name");
- // Get user input
- string input = Console.ReadLine();
- Console.WriteLine("Hello {0}, let's play a game", input);
- while (true)
- {
- Random random = new Random();
- int correctNumber = random.Next(1, 10);
- int guess = 0;
- Console.WriteLine("Guess a number between 1 and 10.");
- while (guess != correctNumber)
- {
- string input1 = Console.ReadLine();
- if (!int.TryParse(input1, out guess))
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("You beat the system, good job.");
- Console.ResetColor();
- continue;
- }
- // Cast to int and put in guess (convert to int)
- guess = Int32.Parse(input1);
- // Match guess to correct number
- if (guess != correctNumber)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Choose a different number");
- Console.ResetColor();
- }
- }
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("Congratulations, you win.");
- Console.ResetColor();
- Console.WriteLine("Do you want to play again?[Y or N]");
- // Get Answer
- string answer = Console.ReadLine().ToUpper();
- if (answer == "Y")
- {
- continue;
- }
- else if (answer == "N")
- {
- return;
- }
- else
- {
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment