Advertisement
mmayoub

Ex01, 26.06.2021

Jun 26th, 2021
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace ConsoleApp1
  6. {
  7.     class Class1
  8.     {
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             Random rnd = new Random();
  13.             int x;
  14.  
  15.             x = rnd.Next(1, 101);
  16.             //Console.WriteLine(x);
  17.  
  18.             int player = rnd.Next(2);
  19.  
  20.  
  21.             Console.Write("Guess my number! Player {0} : ",player);
  22.             int num = int.Parse(Console.ReadLine());
  23.             int c = 1;
  24.            
  25.  
  26.             while (num != x)
  27.             {
  28.                     if (num < x)
  29.                     {
  30.                         Console.WriteLine("My Number is Greater than " + num);
  31.                     }
  32.                     else
  33.                     {
  34.                         Console.WriteLine("My Number is Lower than " + num);
  35.                     }
  36.              
  37.                 if (player == 0)
  38.                     player = 1;
  39.                 else
  40.                     player = 0;
  41.  
  42.                 Console.Write("Guess my number! player {0} : ",player);
  43.                 num = int.Parse(Console.ReadLine());
  44.                 c++;
  45.             }
  46.  
  47.             Console.WriteLine();
  48.             Console.WriteLine("Player{0} is the winner !", player);
  49.             Console.WriteLine("Correct answer! my number is " + x);
  50.             Console.WriteLine("You did it in {0} triales", c);
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement