I need to write a permutation program which takes in a set x number of males and females where they rate each other and then the program will organize them into a pattern of best possible score;

the program works like this

Matt, Dave, Alan; Heather, Sara, Joan

Matt- 3,5,6

Dave- 5,6,8

Alan- 4,2,5

Heather-6,7,8

Sara-4,6,5

Joan-4,2,3

The program will calculate each possible matching to get best possible score; this is achieved by taking the lower rating between the two people from each couple and adding them together to achieve a total score; highest total score is the match, ties are broken by subtracting differences

For example, Matt&Heather- 3, Dave&Sara- 4, Alan&Joan-4; Total score: 11; permute; Matt&Heather - 3, Dave&Joan- 3, Alan&Sara-6; Total Score: 12; permute...

---

My current problem lies in calculating the TotalMax score at the moment. What I'm attempting to do is make a method that calculates TotalMax. This code is going to get the total of a particular set. My first question is about whether or not the (int) casting is correct for p and q[i].ratings. I think what I'm doing is casting an int on the pointer? I believe it's incorrect but as my main is still suffering issues I can't really test this out yet.

The struct Matcher has char name[19] (person's name) and int* ratings (their ratings of the opposite sex) to represent each person; in my main i have created struct Matcher males[] and struct Matcher females[]

compareRate returns -1 if p[i].ratings[i] is smaller than q's, 0 if even, 1 if bigger

---Code://this is to get total score for one set of matches; it will return the //score of the points added together; k=size of array p and q which are equal int getMatchTotal(struct Matcher p[], struct Matcher q[], int k) { int i,total; for(i=0;i<k;i++) { if(compareRate(p[i],q[i],i)==-1) total+=(int)p[i].ratings; else total+=(int)q[i].ratings; } return total; }

My second problem is the permutating part. I have to permute an n amount of people, which is all read from a file, with names and ratings, etc. I'm trying to write a method that needs to permute both the names of the people in the second list(im using females) and the ratings stored in each person at the same time, but I'm having trouble putting this code together. Is a hint possible?

---

I also have a third problem in the main

i dont know why but this crashes my program...cant figure it out, help please?Code:assign each male their ratings int j; for(dud=0;dud<num_people;dud++) { for(j=0;j<num_people;j++) { fscanf(read,"%d",&males[dud].ratings[j]); printf("%d ",males[dud].ratings[j]); } printf("\n"); }