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);
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);
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",

int party (int n)
int days;
int frequency [SIZE] = {0};
days = 1 + rand() % 365;
if (frequency[days] <= 1)
return 1;
return 0;

The same code was round a few days ago, including the same mistakes.

My guess is that this is a "fix the errors" homework assignment just dumped on the board.

thanks for the tip. now i won't waste my time on it.
This article has been dead for over six months. Start a new discussion instead.