adding number guessing game
This commit is contained in:
26
C# Full Course for free/11.Random Game.cs
Normal file
26
C# Full Course for free/11.Random Game.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
int result = random.next(1,10);
|
||||||
|
|
||||||
|
Console.Write("Pick a number : ");
|
||||||
|
int guess = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
while(result != guess)
|
||||||
|
{
|
||||||
|
if(result < guess)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Too high !");
|
||||||
|
Console.Write("Pick a number : ");
|
||||||
|
guess = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
}else if(result < guess)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Too low !");
|
||||||
|
Console.Write("Pick a number : ");
|
||||||
|
guess = Convert.ToInt32(Console.ReadLine());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("You Win ! ");
|
||||||
Reference in New Issue
Block a user