-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessTheNumberGame.cs
More file actions
44 lines (39 loc) · 1.19 KB
/
Copy pathGuessTheNumberGame.cs
File metadata and controls
44 lines (39 loc) · 1.19 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
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GuessTheNumberGame
{
class Program
{
static Random rnd = new Random();
public static int RandomNumber()
{
int NewNumber = rnd.Next(9) + 1;
return NewNumber;
}
static void Main(string[] args)
{
int actualNumber, guess;
Console.WriteLine("Please enter a number in between 1 and 9: \n");
char gameEnd = 'y';
actualNumber = RandomNumber();
Console.Write(actualNumber);
guess = Convert.ToInt32(Console.ReadLine());
do
{
while (guess != actualNumber)
{
Console.Write(guess);
guess = Convert.ToInt32(Console.ReadLine());
if (guess == actualNumber)
gameEnd = Console.ReadKey().KeyChar;
else
Console.WriteLine("Try Again!");
}
Console.WriteLine("Want to play Again? Y/N");
} while (gameEnd == 'y');
}
}
}