birthday paradox problem

Sep 15, 2011 at 7:10pm
hello all.....im extremly new to c++ and trying to take this in collage and have the following homework to do:
Instructions:
The Birthday Paradox. (This problem is based on BUT IS NOT THE SAME AS programming project 8 of the text. Please read the directions carefully and be sure to fulfill all requirements of the problem.) The birthday paradox is that there is a surprisingly high probability that two people in the same room happen to share the same birthday. By birthday, we mean the same day of the year (ignoring leap years), but not the exact birthday including the birth year or time of day. The assignment is to write a program that does the following
a. Approximates the probability that two people in the same room have the same birthday, for each case of 2 to 50 people in the room.

b. Calculates the theoretical probability that two people in the same room have the same birthday, for each case of 2 to 50 people in the room, (yes, it is known that the formula for this can be found on the internet, but it’s more fun to figure this out for yourself. I leave it to you to determine how you arrive at the appropriate formula).

c. Calculates the percent difference between a and b for each number of people in the room, 2 to 50, where Percent Difference = Absolute Value(Actual Probability – Observed Probability) / Actual Probability * 100.

The output of the program should be a table with 4 columns with the following headings: Number of People, Observed Probability, Actual Probability, % Difference.

The program should use simulation to approximate each probability. Over many trials (say, 5000), randomly assign birthdays to everyone in the room. Count up the number of times at least two people have the same birthday, and then divide by the number of trials to get an estimated probability that two people share the same birthday for a given room size.

i have gotten part way through it but do not know how to complete. i will post the code any help is appreciated
Sep 15, 2011 at 7:10pm
// this is the birthday paradox program
// for 2 - 50 people, it detemines the chances of any 2 of the group to have their birthday on the same day

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;

int count;
float percentcalculate;
float percentrandom;
float percentdiff;
int DAYS = 365;
int TESTCOUNT = 5000;
int people;
int i;
int test;

void main ()

{
cout << "this is the birthday paradox program" << endl;
cout << "this determines, from 2 - 50 people" << endl;
cout << "the observed and actual probability" << endl;
cout << "of any of those 2 people to share the same birthday" << endl;
cout << "going off of only month and day" << endl;
cout << "people" ;
cout.width (10);
cout << "ob. prob.";
cout.width (10);
cout << "ac. prob.";
cout.width (10);
cout << "percent diff" << endl;

for (count = 2; count <=50; count ++);
{
int people = count;
for (test = 1; test <= TESTCOUNT; test ++);
{
int birthday [count];
birthday [count] = rand () % 365 + 1;
if (birthday [count] = 0
{
birthday = 1;
}
else if (birthday [count] = 1)
samecount ++;

}

percentrandom = ;
percentcalculate = ;
percentdiff = abs(percentrandom - percentcalculate) * 100;
cout << people;
cout.width(10);
cout << percentrandom;
cout.width(10);
cout << percentcalculate;
cout.width(10);
cout << percentdiff << endl;
count++;
}


}




Sep 15, 2011 at 7:26pm
Use [ code ] [ /code ] tags around your code.

Describe exactly with what you do have problems.
How is it a "paradox" if two people share the same birthday? *scratches*
Sep 17, 2011 at 12:27pm
ok as far as the "paradox" im not sure, i think its that at 23 people thier is a 50% chance that any 2 people have their birthday on same month and day. ok here is how i understand this.....for a group of people, starting at 2 people and ending at 50 people, i need to have 5000 tests comparing to see how many times for each group ot of those 5000 tests i shows that any two people of that group share the same birthday (i.e. for each test, generate a random number from 1 - 365 and compare them and if nothing is equal its false, but as soon as thier is one set where two of those numbers are equal its true and i can quit calculateing). once those 5000 test cases are done, i need to display the number of people for the case, the observed times that the random number generator showed that 2 numbers were equal, the statistical chances of it happening, and the differance
Sep 18, 2011 at 9:14pm
i also dont understand what is tags?
Sep 19, 2011 at 2:55am
It's called a paradox because at first glance it seems counterintuitive that there's a 50% of two people in a group of 23 people sharing the same birthday, rather than the expected probability of 6.297%. The key is that we're not asking for the probability of someone having one particular birthday.

[code]
#include <iostream>

int main(){
std::cout <<"Hello, World!\n";
}
[/code]
becomes
1
2
3
4
5
#include <iostream>

int main(){
    std::cout <<"Hello, World!\n";
}
Topic archived. No new replies allowed.