-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (49 loc) · 1.61 KB
/
Program.cs
File metadata and controls
52 lines (49 loc) · 1.61 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
48
49
50
51
52
namespace ProgrammingChallenges;
public interface IChallange
{
string Name();
void Start();
}
class Program
{
static private List<IChallange> ChallangeList = new List<IChallange>()
{
new GuessTheNumber(),
new HeadsTails(),
new TemperatureConverter()
};
static void Main()
{
Console.WriteLine("Hi!");
Console.WriteLine("This is a program which aggregates all the other mini programs that I wrote for ProgrammingChallanges.");
Console.WriteLine("Here are the ones that I did already:");
// Iterating in array with programs
Console.WriteLine();
for (int i = 0; i < ChallangeList.Count(); i++)
{
// Add leading 0 if number is lesser that 10, ex. 5 to 05
if (i < 9)
{
Console.WriteLine($" 0{i + 1} - {ChallangeList[i].Name()}");
}
else
{
Console.WriteLine($" {i + 1} - {ChallangeList[i].Name()}");
}
}
Console.WriteLine();
Console.WriteLine("Type number to select mini program.");
Console.Write("Number: ");
string? input = Console.ReadLine();
// Try input number and start challenge with that number
// or give error when there isn't any
int inputNumber;
while (!int.TryParse(input, out inputNumber))
{
Console.WriteLine("You didn't type number in correct format. Please try again using only digits.");
input = Console.ReadLine();
}
Console.Clear();
ChallangeList[inputNumber - 1].Start();
}
}