Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <math.h>
- #define hundredm 100
- using namespace std;
- int main()
- {
- // Set this to the number of iterations you want(higher is more accurate)
- int iterations = 100;
- //Some init code
- int thesize = hundredm; // Sets the number of people
- cout << "Starting, using " << thesize << " people and " << iterations << " iterations" << endl;
- int n[hundredm];// Declars array to count number of wins
- // some variables for logic
- int win = 0;
- int lose = 0;
- bool exit;
- int which = 0;
- // This makes sure you go through like ten thousand iterations
- for (int Q = 0; Q< iterations; Q++){
- // Prints some info into console
- if (Q % 200 == 0) cout << "Run #" << Q << ", " << win << " wins so far" << endl;
- // resets all the values for logic
- for (int i = 0; i < thesize; i++){
- n[i] = 0;
- }
- exit = false;
- // Keeps going until you lose or win
- while (!(exit)){
- which = (int)( hundredm * rand() / RAND_MAX ); // Selects who won
- n[which]++; // adds to their score
- //if which = 0 then you win, else someone else won
- // if you win, or someone wins three times, exits
- if ((which ==0)||(n[which] >= 3)){
- exit = true;
- }
- }
- // Checks to see if you won or lost
- if (which == 0) {
- win ++;
- } else lose ++;
- }
- // This shows you the answer
- cout << "You won " << win << " times out of " << iterations << " runs" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement