-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
56 lines (44 loc) · 1.35 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
43
44
45
46
47
48
49
50
51
52
53
54
using System;
namespace guessinggame;
class guessinggame
{
static void Main(string[] args)
{
int playerGuess = 0;
int computerNum = 0;
int numOfGuesses = 0;
Random rnd = new Random();
Console.WriteLine("Let's Play a guessing game!");
Console.WriteLine("I am thinking of a number between 1 and 20.");
Console.WriteLine("Enter a guess or type -1 to exit.");
computerNum = rnd.Next(1, 20);
while(true)
{
Console.WriteLine("What is your guess?");
playerGuess = int.Parse(Console.ReadLine());
numOfGuesses++;
if (playerGuess > computerNum)
{
Console.WriteLine("Your guess is to large!");
}
else if (playerGuess < computerNum)
{
Console.WriteLine("Your guess is to small!");
}
else if (playerGuess == computerNum)
{
Console.WriteLine("Congratulations!");
break;
}
else if (playerGuess == -1)
{
break;
}
else
{
Console.WriteLine("That is an incorrect value!");
}
}
Console.WriteLine($"You got it in {numOfGuesses} guesses.");
}
}