Hey guys, i'm having trouble with having to simulate a user entered number of parties and user entered number of guests. I am supposed to have a function with the prototype int party(int n) that will simulate one group at a time with n guests. I have to assign each guest with a random birthday and have the program check to see if two of members have the same birthday. If one party has two guests with the same birthday, the function returns 1. If all the birthdays at one party are different, the function returns 0.

Then main() counts the number of 1's, divides it by the number of parties and prints out a percentage.

With 30 guests and 1000 parties, it should output about a 70% chance, but I’m getting weird percentages like 33.3%..Here's what I have so far...

```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 366
int party (int n);
main()
{
int trial, bday, n, guests;
float percent, total, i;
printf("Enter the number of guests: ");
scanf("%d", &guests);
printf("Enter the number of parties: ");
scanf("%d", &trial);
srand(time(NULL));
for (i=1; i<=trial; i++)
{
bday = party(n);
}
if (bday == 1)
{
total += 1;
}
percent = (float)total/guests*1000.0;
printf("The Probablity of people with the same birthday is %0.2f%%\n",
percent);
}
int party (int n)
{
int days;
int frequency [SIZE] = {0};
days = 1 + rand() % 365;
++frequency[days];
if (frequency[days] <= 1)
{
return 1;
}
else
{
return 0;
}
}
```

*Edited 6 Years Ago by zyx*: n/a