-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindRandomNumber
42 lines (35 loc) · 1.02 KB
/
findRandomNumber
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FindRandom
{
class Program
{
static void Main(string[] args)
{
Random rand = new Random();
int randomNum = rand.Next(1, 1000);
int count = 1;
Console.WriteLine("guess a number:");
while(true)
{
int guess = Convert.ToInt32( Console.ReadLine());
if (guess > randomNum)
{
Console.WriteLine("Too big.Try again");
count++;
}else if(guess<randomNum)
{
Console.WriteLine("Too small.Try again");
++count;
}else if(guess==randomNum)
{
Console.WriteLine($"That's correct you found the number in {count} tries!");
return;
}
}
}
}
}