Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Random rand = new Random();
- int number = rand.Next(20) + 1;
- Console.WriteLine("i've picked a number from 1 to 20. guess it!");
- int guess = 0;
- while (guess != number)
- {
- Console.Write("guess: ");
- string line = Console.ReadLine();
- line = line.Trim();
- bool validGuess = true;
- try { guess = int.Parse(line); }
- catch { validGuess = false; }
- if (validGuess)
- {
- if (guess < 1 || guess > 20) Console.WriteLine("that wasn't even between 1 and 20!");
- else if (guess != number) Console.WriteLine("that's not the number!");
- else Console.WriteLine("you're right! it was " + number + "!");
- }
- else Console.WriteLine("that wasn't a number.");
- }
- Console.WriteLine("good job, you won!");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement