-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (38 loc) · 1.52 KB
/
Copy pathProgram.cs
File metadata and controls
47 lines (38 loc) · 1.52 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
45
46
47
using System;
namespace NumberGuessing
{
class Program
{
static void Main(string[] args)
{
// guess the random number generated between 0 & 100
Random r = new();
int magicNumber = r.Next(1, 100);
int guessCount = 0;
bool win = false;
Console.WriteLine("* Welcome to the Guessing Game! *");
Console.WriteLine("=================================");
do
{
Console.WriteLine("Guess the number between 1 & 100:");
string s = Console.ReadLine();
int i = int.Parse(s);
if (i > magicNumber) {
Console.WriteLine("To high, try again...");
} else if (i < magicNumber) {
Console.WriteLine("To low, try again...");
} else if (i == magicNumber) {
Console.WriteLine("=================================");
Console.WriteLine("************ YOU WIN ************");
Console.WriteLine("=================================");
win = true;
}
guessCount++;
Console.WriteLine();
} while (win == false);
Console.WriteLine("Thanks for playing, total guesses: {0}", guessCount.ToString());
Console.Write("Press any key to exit");
Console.ReadKey(true);
}
}
}