HELP!!!!!!!!!!

i need to create a program that finds common interests in people to match them up. I have an array of men and an array of women of the class CIndividual. I think everything else in my program is right except i don't know how to "Search the array men and print the information for each male who shares at least 3 common interests with the women. this is what i have:



int match(CIndividual men[], CIndividual women[], int numMen, int numWomen){

int i;

for(i = 0; i < numWomen; i++){
// starting from 0, go through the foor loop until you have gone through
// every woman

// idk if the following if statements was the most efficient way to do this?
if(women[i].interests.movies == men.interests.movies // the following checks every possiblity
&& women[i].interests.music == men.interests.music // for matching based on 3 similarities
&& women[i].interests.romance == men.interests.romance)
return 1;
else if(women[i].interests.movies == men.interests.movies
&& women[i].interests.music == men.interests.music
&& women[i].interests.sports == men.interests.sports)
return 1;
else if(women[i].interests.movies == men.interests.movies
&& women[i].interests.music == men.interests.music
&& women[i].interests.travel == men.interests.travel)
return 1;
else if(women[i].interests.music == men.interests.music
&& women[i].interests.romance == men.interests.romance
&& women[i].interests.sports == men.interests.sports)
return 1;
else if(women[i].interests.music == men.interests.music
&& women[i].interests.romance == men.interests.romance
&& women[i].interests.travel == men.interests.travel)
return 1;
else if(women[i].interests.romance == men.interests.romance
&& women[i].interests.sports == men.interests.sports
&& women[i].interests.travel == men.interests.travel)
return 1;
else if(women[i].interests.romance == men.interests.romance
&& women[i].interests.sports == men.interests.sports
&& women[i].interests.movies == men.interests.movies)
return 1;
else if(women[i].interests.sports == men.interests.sports
&& women[i].interests.travel == men.interests.travel
&& women[i].interests.movies == men.interests.movies)
return 1;
else if(women[i].interests.sports == men.interests.sports
&& women[i].interests.travel == men.interests.travel
&& women[i].interests.music == men.interests.music)
return 1;
// if any match is found it returns 1
else
return 0;
// otherwise it returns 0
}
}




MY PROBLEM IS THAT I DON'T KNOW HOW TO COMPARE EACH WOMAN TO THE ENTIRE ARRAY OF MEN.

THE ERROR I GET IS: request for member 'interests' in 'men' which is non class type CIndividual

You need two loops. Simply 1 for the men and an inside one for the women. The inside one should usually contain the larger amount of gender. This allows for you to check individually with the other for loop a male with all females... Then increments checking the next male with all females. You probably also want to use a void function... Returning true with the data you provided will be hard to actually print out the actual individuals you've fount that are compatible with each other.


Last edited on
I believe your program is a classic example of when operator overloading is useful and easier to read also. You can define a == operator overload for your class and your comparison code will be very much shorter.

E.g
if (women[i] == men[i]) do something...

Then inside your operator==(const CIndividual&) you will implement how they are compared as "equal" to each other.
Topic archived. No new replies allowed.