Advertisement
Gibstick__

Untitled

Jul 27th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <math.h>
  4.  
  5. #define hundredm 100000000
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.     // Set this to the number of iterations you want(higher is more accurate)
  13.         int iterations = 10000;
  14.  
  15.         //Some init code
  16.         int thesize = hundredm; // Sets the number of people
  17.         cout << "Starting, using " << thesize << " people and " << iterations << " iterations" << endl;
  18.         int n[hundredm];// Declars array to count number of wins
  19.  
  20.         // some variables for logic
  21.         int win = 0;
  22.         int lose = 0;
  23.         bool exit;
  24.         int which = 0;
  25.  
  26.         // This makes sure you go through like ten thousand iterations
  27.         for (int Q = 0; Q< iterations; Q++){
  28.  
  29.             // Prints some info into console
  30.             if (Q % 200 == 0) cout << "Run #" << Q << ", " << win << " wins so far" << endl;
  31.  
  32.             // resets all the values for logic
  33.             for (int i = 0; i < thesize; i++){
  34.                 n[i] = 0;
  35.             }
  36.             exit = false;
  37.  
  38.             // Keeps going until you lose or win
  39.             while (!(exit)){
  40.  
  41.                 which = (int)( hundredm * rand() / RAND_MAX ); // Selects who won
  42.                 n[which]++; // adds to their score
  43.  
  44.                 //if which = 0 then you win, else someone else won
  45.  
  46.                 // if you win, or someone wins three times, exits
  47.                 if ((which ==0)||(n[which] >= 3)){
  48.                     exit = true;
  49.                 }
  50.             }
  51.  
  52.             // Checks to see if you won or lost
  53.             if (which == 0) {
  54.                 win ++;
  55.             } else lose ++;
  56.         }
  57.  
  58.         // This shows you the answer
  59.         cout << "You won " << win << " times out of " << iterations << " runs" << endl;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement