-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
70 lines (61 loc) · 1.66 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
namespace GuessingGame_ConsoleApp
{
internal class Program
{
static public int rInt;
static public int numAnswer;
static void Main(string[] args)
{
Random r = new Random();
rInt = r.Next(1, 100);
Console.WriteLine("Guess what number I am thinking of! Its between 1 and 100");
Check();
}
static private void Check()
{
string answer = Console.ReadLine();
answer = answer.Trim();
bool isNumeric = int.TryParse(answer, out _);
if (isNumeric)
{
numAnswer = Int32.Parse(answer);
}
else
{
Console.WriteLine("That is not a number...");
Check();
}
if(numAnswer > 0 && numAnswer < 101)
{
Play(numAnswer);
}
else
{
Console.WriteLine("The number must be above zero and below 101.");
Check();
}
}
static private void Play(int answer)
{
if(answer > rInt)
{
Console.WriteLine("The number I am thinking of is lower. Try again.");
}
else if(answer < rInt)
{
Console.WriteLine("The number I am thinking of is higher. Try again.");
}
else
{
Console.WriteLine(rInt.ToString()+" is correct!");
End();
}
Check();
}
static int End()
{
return 0;
}
}
}