-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02.HeadsTails.cs
More file actions
48 lines (44 loc) · 1.28 KB
/
02.HeadsTails.cs
File metadata and controls
48 lines (44 loc) · 1.28 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
namespace ProgrammingChallenges;
class HeadsTails: IChallange
{
public string Name() => "Heads Or Tails";
private static int Random()
{
// Generating random number
Random Random = new Random();
return Random.Next(0, 2);
}
public void Start()
{
// Creating random number
bool Heads = Convert.ToBoolean(Random());
Console.WriteLine("Guess if this will be 'Heads' or 'Tails'.");
Console.Write("Your guess: ");
string? input = Console.ReadLine();
switch(input)
{
case "Heads":
if(Heads)
{
Console.WriteLine("Congratulations! You guessed right.");
} else
{
Console.WriteLine("Sorry! You didn't guess right.");
}
break;
case "Tails":
if (Heads)
{
Console.WriteLine("Sorry! You didn't guess right.");
}
else
{
Console.WriteLine("Congratulations! You guessed right.");
}
break;
default:
Console.WriteLine("Incompatible answer!");
break;
}
}
}