I have to create a program that handles random birthdays between 2 and 50 students (depending on what the user inputs), and calculates the random birthday (1 to 365) and then determines whether or not students share the sam birthday, and how many students share it. I'm stuck on how to get the system to tell me if there are shared birthdays....any ideas?
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
void main()
{
int numStudents, tmp, cnt, i, j;
double Probability, Power;
cout << "Enter Number of Students in The Room: " << endl;
cin >> numStudents;
cout << endl;
int* array=new int[numStudents];
Power = (numStudents * (numStudents - 1)) / 2;
Probability = (1 - pow((364.0)/(365.0) , Power));
cnt = 0;
while (cnt < numStudents)
for (i=0; i < numStudents; i++)
{
array[i] = rand() % 365 + 1;
cout << array[i] << endl;
cnt++;
}
cout << "Number of Students is: " << cnt << endl;
cout << "Probability of sharing DOB: " << Probability << endl;
for(i=0;i < numStudents ;i++)
{
tmp=array[i];
for(int j=0;j<numStudents;j++)
{
if(array[j]==tmp && (j>i))
{
cout << array[j] << endl;
}
}
}
}