Advertisement
mess0011

projk1

Nov 13th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication29
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random number = new Random();
  14.             int nr1 = number.Next(1, 10);
  15.             int guess = 0;
  16.             int counter = 0;
  17.  
  18.             Console.WriteLine("Iยดm thinking of a number between 1 to 10.");
  19.  
  20.             while (guess != nr1)
  21.             {
  22.                 Console.WriteLine("You are at the {0} try.", counter + 1);
  23.  
  24.                 guess = Convert.ToInt32(Console.ReadLine());
  25.  
  26.                 if (guess < nr1)
  27.                 {
  28.                     Console.WriteLine("No, the number I have in mind is higher than {0}", guess);
  29.                 }
  30.                 else if (guess > nr1)
  31.                 {
  32.                     Console.WriteLine("no, the number I have in mind is lower than {0}", guess);
  33.                 }
  34.                 counter++;
  35.                 if (counter == 5)
  36.                 {
  37.                     Console.WriteLine("You have lost the game.");
  38.                     break;
  39.                 }
  40.             }
  41.  
  42.             Console.WriteLine("Welldone! the answer was {0}", nr1);
  43.             Console.ReadLine();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement