Question
Coding in C++ and can not seem to figure out how to finish this code I am working on I will post the question as
Coding in C++ and can not seem to figure out how to finish this code I am working on I will post the question as long with some code I have written so far, I would appreciate if you either fix up my code or you can write your own.
Question - The birthday paradox says that the probability that two people in a room will have the same birthday is more than half as long as the number of people in the room (n), is more than 23. This property is not really a paradox, but many people find it surprising. Design a C++ program that can test this paradox by a series of experiments on randomly generated birthdays, which test this paradox for n = 5,10,15,20,...,100. You should run at least 10 experiments for each value of n and it should output, for each n, the number of experiments for that n, such that two people in that test have the same birthday.
Code so far -
#include
#include
#include
using namespace std;
bool check(int d[], int m[], int siz)
{
int count = 0;
for (int i = 0; i for (int j = 0; j if (i != j && d[i] == d[j] && m[i] == m[j]) count++; return count; } int main() { int bday = 0; srand(time(NULL)); //int o_day=rand()%31; //int o_month=rand()%13; int people[] = { 5,10,20,23,25,50,60,72,80,90,100 }; for (int k = 0; k<10; k++) { bday = 0; cout << k << " experiment :" << endl; for (int i = 0; i<11; i++) { int days[people[i]]; int mths[people[i]]; for (int j = 0; j { days[j] = 1 + rand() % 30; mths[j] = 1 + rand() % 12; //cout< } bday += check(days, mths, people[i]); cout << people[i] << " have " << bday << " on the same date" << endl; } } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started