-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
112 lines (90 loc) · 3.07 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
//namespace
namespace ConsoleApp1
{
//Main Class
internal class Program
{
//Entry Point Method
static void Main(string[] args)
{
//appInfo give information of app
appInfo();
// greet the user
greetUser();
string answer = "Y";
label:
while (answer == "Y")
{
//Init Correct number
//int correctNumber = 7;
//new random number
Random random = new Random();
int correctNumber = random.Next(1, 10);
//Init guess var
int guess = 0;
//Guess
printColorMsg(ConsoleColor.DarkCyan, "Guess a number between 1 to 10 \n");
//loop for user to guess
while (guess != correctNumber)
{
//Get user input
string input = Console.ReadLine();
//validate input
if (!int.TryParse(input, out guess))
{
printColorMsg(ConsoleColor.Red, "Please enter an actual number....");
}
// Cast to int and put in guess
guess = Int32.Parse(input);
if (guess != correctNumber)
{
printColorMsg(ConsoleColor.Red, "Wrong number guess again.... ");
}
}
//Output Success msg
printColorMsg(ConsoleColor.DarkYellow, "You are CORRECT!....");
//play again
while (true)
{
Console.WriteLine("Do you want to play again ? [Y or N]");
answer = Console.ReadLine().ToUpper();
if (answer == "Y")
{
goto label;
}
else if (answer == "N")
{
return;
}
else
{
printColorMsg(ConsoleColor.Red,"Choose Valid option");
}
}
}
}
static void appInfo()
{
string appName = "Number Guesser";
string appVersion = "1.0.0";
string appAuthor = "Naman Mehta";
printColorMsg(ConsoleColor.DarkGreen, "Number Guesser : Version 1.0.0 by Naman Mehta");
}
static void greetUser()
{
//Ask user input
Console.WriteLine("What is your name ? ");
//get user input
string inputName = Console.ReadLine();
Console.WriteLine("Hola! {0}, Let play a game.... \n", inputName);
}
//print color msg
static void printColorMsg(ConsoleColor color, string text)
{
Console.ForegroundColor = color;
Console.WriteLine(text);
Console.ResetColor();
}
}
}