Guest User

Untitled

a guest
Apr 22nd, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CoinFlip
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             startFlippin();
  14.         }
  15.  
  16.         public static void startFlippin()
  17.         {
  18.             Console.WriteLine("Please enter the amount of coin flips");
  19.  
  20.             string userInput = Console.ReadLine();
  21.  
  22.             if (Int32.TryParse(userInput, out int x))
  23.             {
  24.                 Random rnd = new Random();
  25.                 int heads = 0;
  26.                 int tails = 0;
  27.                 List<int> outcomes = new List<int>();
  28.  
  29.                 for (int i = 0; i < x; i++)
  30.                 {
  31.                     int tailsheads = rnd.Next(0, 2);
  32.  
  33.                     if (tailsheads == 0)
  34.                     {
  35.                         tails++;
  36.                     }
  37.                     else
  38.                     {
  39.                         heads++;
  40.                     }
  41.  
  42.                     outcomes.Add(tailsheads);
  43.                 }
  44.  
  45.                 Console.WriteLine("Your results: ");
  46.  
  47.                 for (int i = 1; i <= outcomes.Count; i++)
  48.                 {
  49.                     Console.Write("{0,-6}", outcomes[i-1]);
  50.                     if (i % 5 == 0) Console.WriteLine();
  51.                 }
  52.  
  53.                 Console.WriteLine("Summed tails: " + tails);
  54.                 Console.WriteLine("Summed heads: " + heads);
  55.                 Console.ReadKey();
  56.                 startFlippin();
  57.             }
  58.             else
  59.             {
  60.                 Console.WriteLine("That's not a number, please try again");
  61.                 Console.ReadKey();
  62.                 Console.Clear();
  63.                 startFlippin();
  64.             }
  65.         }
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment