Hello everyone! I am new to this forum (and C programming) but I hope that I will be able to master C help anyone out with problems in the coming months. But I am having trouble with my own program for an assignment.
I am asked to simulate a user entered number of birthday parties and user entered number of guests at each party. I am supposed to have a function with the prototype int party(int n) that will simulate one party 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 the guests 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.
I got most of the code done, but I am stuck where I am supposed to check if any two birthdays are the same. I cannot think of a way to write that code and make it work. Any help would be greatly appreciated.
#include
#include
int party(int g);
main()
{
int guests, j;
long int parties, samebday, diffbday, count, result;
printf(“Enter the number of parties: “);
scanf(“%ld”, &parties);
printf(“Enter the number of guests: “);
scanf(“%d”, &guests);
srand(time(NULL));
samebday = 0;
diffbday = 0;
for (j = 1; j <= parties; j++)
{
party(guests);
/*count = party(result);
printf("%d \n", count);
if (count == 1)
samebday++;
if (count == 0)
diffbday++;
*/
}
//printf("%d \n", samebday);
//printf("%d \n", diffbday);
system("PAUSE");
return 0;
}
int party(int g)
{
int i, j, bdays[g];
long int parties, hold;
for(i = 0; i < g; i++)
{
bdays[i] = 1 + rand() % 365;
printf("%d, %d \n", i, bdays[i]);
//INSERT CODE HERE TO CHECK IF ANY B-DAYS IN ONE PARTY MATCH
//If any 2 match, return 1. If none match, return 0
}
}