Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CoinFlip
- {
- class Program
- {
- static void Main(string[] args)
- {
- startFlippin();
- }
- public static void startFlippin()
- {
- Console.WriteLine("Please enter the amount of coin flips");
- string userInput = Console.ReadLine();
- if (Int32.TryParse(userInput, out int x))
- {
- Random rnd = new Random();
- int heads = 0;
- int tails = 0;
- List<int> outcomes = new List<int>();
- for (int i = 0; i < x; i++)
- {
- int tailsheads = rnd.Next(0, 2);
- if (tailsheads == 0)
- {
- tails++;
- }
- else
- {
- heads++;
- }
- outcomes.Add(tailsheads);
- }
- Console.WriteLine("Your results: ");
- for (int i = 1; i <= outcomes.Count; i++)
- {
- Console.Write("{0,-6}", outcomes[i-1]);
- if (i % 5 == 0) Console.WriteLine();
- }
- Console.WriteLine("Summed tails: " + tails);
- Console.WriteLine("Summed heads: " + heads);
- Console.ReadKey();
- startFlippin();
- }
- else
- {
- Console.WriteLine("That's not a number, please try again");
- Console.ReadKey();
- Console.Clear();
- startFlippin();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment