bhalash

Baron's Deathcharger calculator. :/

May 28th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. public class Probability
  6. {
  7.     static void Main()
  8.     {
  9.         Hello();
  10.         Input();
  11.     }
  12.  
  13.     static void Hello()
  14.     {
  15.         Console.Clear();
  16.         Console.WriteLine("This is a very simple probability calculator.");
  17.         Console.WriteLine("I wrote it to calculate the probability of the Baron dropping his Deathcharger.");
  18.         Console.WriteLine("\nInstructions:");
  19.         Console.WriteLine("\n1. Consult Wowhead for the percentage chance of X item dropping.");
  20.         Console.WriteLine("2. Determine how many times you are willing to run an event or kill a boss for this drop.");
  21.         Console.WriteLine("3. Input them when requested.");
  22.         Console.Write("\nPress [RETURN] to continue.");
  23.         Console.ReadLine();
  24.         Console.Clear();
  25.     }
  26.  
  27.     static void Input()
  28.     {
  29.         int drop = 0;
  30.         int runs = 0;
  31.  
  32.         drop = ParseInteger("Enter percentage drop rate: \t");
  33.         runs = ParseInteger("Enter number of runs: \t\t");
  34.  
  35.         Console.WriteLine();
  36.         Console.Write("\nThe probability of a drop after {0} runs is {1:P}.\n", runs, Calcutron(drop, runs));
  37.         Console.ReadLine();
  38.     }
  39.  
  40.     static double Calcutron(int drop, int runs)
  41.     {
  42.         // Convert the drop rate percentage into a usable decimal.
  43.  
  44.         double cuml = 1;
  45.         double prob = 0;
  46.  
  47.         prob = 1 - (Convert.ToDouble(drop) / 100);
  48.  
  49.         for (int i = 1; i <= runs; i++)
  50.             cuml *= prob;
  51.  
  52.         cuml = 1 - cuml;
  53.  
  54.         return cuml;
  55.     }
  56.  
  57.     // Parse input.
  58.     static int ParseInteger(string query)
  59.     {
  60.         bool parse      = false;
  61.         int parsedInt   = 0;
  62.  
  63.         do
  64.         {
  65.             Console.Write(query);
  66.             parse = Int32.TryParse(Console.ReadLine(), out parsedInt);
  67.  
  68.             if (!parse)
  69.                 ParseErr();
  70.  
  71.         } while(!parse);
  72.  
  73.         return parsedInt;
  74.     }
  75.  
  76.     // +++++ERRORS++++
  77.     static void ParseErr()
  78.     {
  79.         Console.WriteLine("\nPlease input a valid number!");
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment