-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (33 loc) · 1.04 KB
/
Program.cs
File metadata and controls
36 lines (33 loc) · 1.04 KB
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
namespace NumberGuesser
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Random rnd = new Random();
int secretNumber = rnd.Next(1, 101);
int guess;
int attempts = 0;
do
{
Console.WriteLine("Guess the number (1-100): ");
guess = Convert.ToInt32(Console.ReadLine());
attempts++;
if (guess < secretNumber)
{
Console.WriteLine("Too low! try again.");
}
else if (guess > secretNumber)
{
Console.WriteLine("Too high! Try again");
}
else
{
Console.WriteLine($"Congratulations, {name}! You guessed the number in {attempts} attempts.");
}
} while (guess != secretNumber);
}
}
}