Check for Identical Birthdays in a Specific group size in C++
<p>I am brand new to this site. A friend told me about it and how much it has helped him, so here goes!</p>

<p>I am trying to create a program that will read in a certain size of a group. At this point it will then create random birthdays for each 'member' of the group (a day 1-365) and then compare to see if there were any identical birthdays in that set. The program will do this comparison for a given group size 10,000 times and keep track of how many of those trials yielded an identical birthday and return a percentage of the 10,000 trials in which there was a match.</p>

<p>The problem I am having is that the program will only ever return 100% and each successive run doubles that. So if a user decided to run again with a different group size, the answer then becomes '200%' then '300%' and so on.</p>

<p>Any help with this will be greatly appreciated!</p>

<pre><code>//This program will ask for the number of people in a group and then output
//percentage likelyhood that two birthdays occur on the same day.

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
using namespace std;
int bdays [365];
const int loop = 10000;
int identicalBday;
void setZero (int []);
int totalDoubles (int [], int);


int main()
{
    int grpSize = 1;
    cout &lt;&lt; "This program will ask for the number of people in a group and then output \npercentage likelyhood that two birthdays occur on the same day.";
    cout &lt;&lt; "\nHow many in group (0 quits)? ";
    cin &gt;&gt; grpSize;
    while (grpSize != 0)
    {
        int identicalBday = 0;
        setZero (bdays);
        cout &lt;&lt; "In a group of " &lt;&lt; grpSize &lt;&lt; " the chances that two birthdays are the same is " &lt;&lt; totalDoubles (bdays, grpSize) &lt;&lt; "%." &lt;&lt; endl;
        cout &lt;&lt; "\nHow many in group (0 quits)? ";
        cin &gt;&gt; grpSize;
    }
    cout &lt;&lt; "Thanks for using this program.";
    cin.get();
    cin.get();
    return 0;
}

//Sets all indicies to 0
void setZero (int bdays [])
{
    for (int i = 0; i &lt; 365; i++)
        bdays [i] = 0;
}

//Will add one to the array index associated with the random rumber
//If that index is already equal to 1, then it breaks (at least one other identical birthday exists)
//When it does break, will add one to the indenticalBday, allowing for division at the end
int totalDoubles (int bdays [], int grpSize)
{
    int tmpRand;
    for (int k = 0; k &lt;= loop; k++)
    {   
        for (int i = 0; i &lt;= grpSize; i++)
        {
            srand((unsigned)time(0));
            tmpRand = rand() % 365;
            if (bdays[tmpRand] == 1)
            {
                identicalBday++;
                break;
            }
            else
                bdays [tmpRand]++;
        }

    }
    return (identicalBday/loop)*100;
}
</code></pre>
