Comparing Arrays

I've read the FAQs to this site and understand that we are not supposed to ask for answers to homework. This is a homework question, but I just want a hint, not a solution. I've been doing really well on the weekly assignments thus far but feel like I've hit a brick wall on this one.

We're supposed to have the user choose three movies to rate, and the user's input should be compared to the original 2d array of four reviewers. The program should then use "distance" (this is mandated in the assignment) to determine which of the four reviewers has the closest taste in movies and display that reviewer's ratings of the other movies. This is due tomorrow and I've been working on it for a week with no sudden breakthrough I was wanting... The distance isn't calculating the way I need it to. Any hints would be GREATLY appreciated.

//code removed
Last edited on
^ xor operator
You need to define a square function.

1
2
3
       ( (userRating[0] - reviews[o][0])^2 + (userRating[1] - reviews[o][1])^2 + 
       (userRating[2] - reviews[o][2])^2 + (userRating[3] - reviews[o][3])^2 +
       (userRating[4] - reviews[o][4])^2 + (userRating[5] - reviews[o][5])^2) )
Use a loop instead.
Last edited on
Thank you for your response, ne555. Could you explain what you mean? What is "xor operator"? What do you mean by "define a square function"? I included stdio.h and math.h. And where should I be using a loop instead? The code that you copied is embedded in a for loop.
xor http://en.wikipedia.org/wiki/Bitwise_operation#XOR
1
2
3
int square(int x){
  return /*the square of x*/;
}

Replace the big sum with a for loop
sum_square += square( userRating[K]-reviews[o][K] );
Also note that sqrt will return a float, but distance is an integer. You will lose information.

I included stdio.h and math.h
Those headers are deprecated. Include cstdio and cmath
I'm only a month into my C++ class, so I admit I'm still confused over xor, but I was able to complete the program with your "square" help! Thanks!
Topic archived. No new replies allowed.