Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CS_Fundamentals
- {
- enum HeadsOrTails
- {
- Heads,
- Tails
- }
- class Program
- {
- static void Main()
- {
- HeadsOrTails playerFlip;
- bool valid;
- bool playAgain;
- HeadsOrTails coinFlip;
- HeadsOrTails computerFlip;
- do
- {
- Random randomValue = new Random();
- coinFlip = (HeadsOrTails)randomValue.Next(Enum.GetNames(typeof(HeadsOrTails)).Length);
- computerFlip = = (HeadsOrTails)randomValue.Next(Enum.GetNames(typeof(HeadsOrTails)).Length);
- Console.WriteLine("------------------------------------------------------------------");
- do
- {
- Console.Write("Pick Heads or Tails: ");
- valid = Enum.TryParse<HeadsOrTails>(Console.ReadLine(), true, out playerFlip);
- } while (!valid);
- Console.WriteLine("The coin landed on {0}\n", coinFlip);
- Console.WriteLine("You picked: {0}", playerFlip);
- Console.WriteLine("Computer picked: {0}\n", computerFlip);
- if (playerFlip != coinFlip && computerFlip != coinFlip)
- {
- Console.WriteLine("You both lose");
- }
- else if (playerFlip == coinFlip && computerFlip == coinFlip)
- {
- Console.WriteLine("It's a tie");
- }
- else if (playerFlip == coinFlip && computerFlip != coinFlip)
- {
- Console.WriteLine("You won");
- }
- else
- {
- Console.WriteLine("You lost");
- }
- Console.Write("press 'y' to play again ");
- playAgain = (Console.ReadLine() == "y") ? playAgain = true : playAgain = false;
- }
- while (playAgain);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement