Hey, i'm having trouble with having to simulate a user entered number of groups and user entered number of group members. I am supposed to have a function with the prototype int group(int n) that will simulate one group at a time with n members. I have to assign each member with a random birthday and have the program check to see if two of members have the same birthday. If one group has two members 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.
Here's what I have so far, it assigns each member with a bday,but i'm not sure how to make a loop if two or more members have the same bday and return a 1 or 0...
Any help will be appreciated, thanks!Code:#include <stdlib.h> #include <time.h> int group(int g, int p); main() { int members; long int groups, samebday; srand(time(NULL)); group(members, groups); system("PAUSE"); return 0; } int group(int g, int p) { int members, count, i, j, bdays[40]; long int groups; printf("Enter the number of groups: "); scanf("%ld", &groups); printf("Enter the number of members: "); scanf("%d", &members); for (j = 1; j <= groups; j++) { for(i = 0; i < members; i++) { bdays[i] = 1 + rand() % 365; } } }



LinkBack URL
About LinkBacks



