Probabilistic matchmaking simulation The following is a problem I found on this wiki. What can I do to optimize my algorithm, and make this code more C++11?


  Write a program to discover the answer to this puzzle:"Let's say men
  and women are paid equally (from the same uniform distribution). If
  women date randomly and marry the first man with a higher salary, what
  fraction of the population will get married?"


#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;
#include &lt;ctime&gt;
//#include &lt;cstdlib&gt;

using std::cin;
using std::cout;
using std::endl;
using std::random_shuffle;


const int MIN = 1;
const int MAX = 1000000;
const int MALES = 100;
const int FEMALES = 100;

class Female{
public:
    Female(){isMarried = false;}

    bool isMarried;
    int salary;
};

class Male{
public:
    Male(){isMarried = false;}

    bool isMarried;
    int salary;
};

void marriageTest(std::vector&lt;double&gt; &amp;results){

    double count = 0;
    bool done = false;

    Male male[MALES];
    Female female[FEMALES];

    //Fill array of Females and Males with random salaries ranging from 1 to 10
    for(int i=0; i&lt;100; i++){
        int output = MIN + (rand() % (int)(MAX - MIN + 1));
        i[male].salary = output; //( ͡° ͜ʖ ͡°)
    }
    for(int i=0; i&lt;100; i++){
        int output = MIN + (rand() % (int)(MAX - MIN + 1));
        i[female].salary = output;
    }


    //Start dating
    //Keep dating until the maximum salary of males is lower than minimum salary of females

    do{
        random_shuffle(&amp;male[0], &amp;male[MALES]);               //Shuffle array of males
        random_shuffle(&amp;female[0], &amp;female[FEMALES]);           //Shuffle array of females


        for(int i=0; i&lt;100; i++){                              //Compare a female and male from both arrays
            if(female[i].salary &lt; male[i].salary)
                if(!female[i].isMarried &amp;&amp; !male[i].isMarried){
                    count++;
                    female[i].isMarried = true;
                    male[i].isMarried = true;
                }
        }

        //Check for Maximum Male Salary
        int maxMen = MIN;
        for(int i=0; i&lt;100; i++){
            if(male[i].salary &gt; maxMen &amp;&amp; !male[i].isMarried)
                maxMen = male[i].salary;
        }

        //Check for Minimum Female Salary
        int minWomen = MAX;
        for(int i=0; i&lt;100; i++){
            if(female[i].salary &lt; minWomen &amp;&amp; !female[i].isMarried)
                minWomen = female[i].salary;
        }

        if(maxMen &lt;= minWomen)
            done = true;


    }while(!done);

    results.push_back(count/100);
}

void runTrials(int num_trials, std::vector&lt;double&gt; &amp;results){

    for(int i=0; i&lt;num_trials;i++)
        marriageTest(results);
}

double Percentage(std::vector&lt;double&gt; &amp;results){

    double final = 0;
    int trials = 0;
    for(auto i : results){
        final += i;
        ++trials;
    }

    return final/trials;
}


int main()
{
    int num_trials;
    std::vector&lt;double&gt; results;

    srand(time(NULL));

    cout &lt;&lt; "Number of trials: ";
    cin &gt;&gt; num_trials;

    runTrials(num_trials,results);

    double final = Percentage(results);

    cout &lt;&lt; "Percentage: " &lt;&lt; final &lt;&lt; endl;

    return 0;
}
There doesn't seem to be a need for separate Male and Female structures as they hold the same exact data.  Instead, just have one named Person and create male and female instances of it.

You also don't need classes if you're not going to have any private data; just use structs.

struct Person
{
    bool isMarried;
    int salary;

    Person() : isMarried(false) {}
};




Person males[MALES];
Person females[FEMALES];

Regarding the use of C++11, you can start by removing both std::srand() and std::rand() and replacing them with functionality from the &lt;random&gt; library, particularly std::shuffle().