First problem:

Run-Time Check Failure #2 - Stack around the variable 'Set' was corrupted.

I get this when I select menu 2 to check the birthday paradox.

Second problem:

When the results are displayed, my matches are too high. I should be getting 50%, maybe a little more, out of a set of 1000. I am getting more matches between 600 and 700 out of a 1000. So my "paradox" is too high.

Third problem:

For the life of me, I cannot discover why my Average formula isn't working in the DisplayBirthdayParadoxResults function. It always comes out to 0% when it is displayed.

#include <iostream> #include <ctime> #include <iomanip> using namespace std; void DisplayMenu(); void MenuChoice(char Choice); void VerifyBirthdayParadox(); void DisplayBirthdaySet(); void GenerateBirthdaySet(int BirthdaySet[]); void SelectionSort(int List[], int Last); void DisplayBirthdayParadoxResults(int Matches); const int SAMPLE_SIZE = 23; const int NUMBER_OF_SETS = 1000; const int DASH_LENGTH = 60; int main() { char Choice; srand((unsigned)time(0)); do { Choice = '\0'; DisplayMenu(); cin>>Choice; cout<<"\n"; MenuChoice(Choice); } while(Choice != 'e' && Choice != 'E'); } void DisplayMenu() { cout<<"1) Explain birthday paradox\n"; cout<<"2) Check birthday paradox by generating 1000 sets of birthdays\n"; cout<<"3) Display one set of 23 birthdays\n"; cout<<"E) Exit\n\n"; } void MenuChoice(char Choice) { switch(Choice) { case '1': cout<<"If 23 people are chosen at random, then the chances are more than 50%\n" <<"that at least two will have the same birthday!\n\n"; break; case '2': VerifyBirthdayParadox(); break; case '3': //DisplayBirthdaySet(); cout<<"Menu 3\n\n"; break; case 'E': case 'e': break; default: cout<<"Invalid selection\n\n"; } } void VerifyBirthdayParadox() { int Set[SAMPLE_SIZE]; int NumberOfMatches = 0; for(int k = 0; k <= NUMBER_OF_SETS; k++) { GenerateBirthdaySet(Set); for(int j = 0; j <= SAMPLE_SIZE; j++) { if(Set[j] == Set[j - 1]) NumberOfMatches++; } } DisplayBirthdayParadoxResults(NumberOfMatches); } void GenerateBirthdaySet(int BirthdaySet[]) { for(int i = 0; i < SAMPLE_SIZE; i++) BirthdaySet[i] = (rand() % 365) + 1; SelectionSort(BirthdaySet, SAMPLE_SIZE); } void DisplayBirthdayParadoxResults(int Matches) { int Average = (Matches / NUMBER_OF_SETS) * 100; char DashLine[DASH_LENGTH]; cout<<"Generating "<<NUMBER_OF_SETS<<" sets of "<<SAMPLE_SIZE <<" birthdays and checking for matches...\n\n"; cout<<"Results : "<<Matches<<" out of "<<NUMBER_OF_SETS<<" (" <<setprecision(1)<<Average <<"%) of the sets contained matching birthdays\n"; for(int i = 0; i < DASH_LENGTH; ++i) { DashLine[i] = '='; cout<<DashLine[i]; } cout<<"\n\n"; }

Thanks ahead of time for any help you can bring me to this.