-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (37 loc) · 973 Bytes
/
Program.cs
File metadata and controls
40 lines (37 loc) · 973 Bytes
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
int theNumber=new Random().Next(20);
bool keepGoing=true;
Console.WriteLine("Let's play 'Guess the Number!'");
Console.WriteLine("I am thinking of a number between 0 and 20.");
Console.WriteLine("Enter your guess, or -1 to give up");
int guessNum=0;
int guessCount=0;
do{
Console.WriteLine("what's your guess?");
string theGuess=Console.ReadLine();
bool result=Int32.TryParse(theGuess, out guessNum);
if (!result)
{
Console.WriteLine("That does not look like a number . Try again.");
}
else{
if(guessNum == -1)
{
Console.WriteLine("I was thinking of {theNumber}");
keepGoing=false;
}
else
{
guessCount++;
}
if (guessNum==theNumber)
{
Console.WriteLine($"You got it in {guessCount} guesses!!");
keepGoing=false ;
}
else
{
Console.WriteLine("Nope, {0} than that",guessNum<theNumber?"higher":"lower");
}
}
}
while(keepGoing);