-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
42 lines (36 loc) · 1.27 KB
/
Program.cs
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
Console.WriteLine("Guess the number drawn by the computer in the range of 1 to 10!");
Random random = new Random();
int a = random.Next(1, 10);
int b;
int howMany = 0;
Console.Write("Please write the number: ");
do
{
b = int.Parse(Console.ReadLine());
if (b <= 10 && b >= 1)
{
howMany++;
if (b == a)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Congratulations! You guessed the number in {0} total!", howMany);
Console.ForegroundColor = ConsoleColor.White;
}
else if (b > a)
{
Console.WriteLine("Unfortunately! The number you entered is greater than the nummber randomly selected");
Console.Write("Please write the number again: ");
}
else
{
Console.WriteLine("Unfortunately! The number you entered is lower than the nummber randomly selected");
Console.Write("Please write the number again: ");
}
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("The number you entered is out of range! Please enter the number again: ");
Console.ForegroundColor = ConsoleColor.White;
}
} while (a != b);