So I've got a movie review program (4 reviewers) (6 movies) and I need to find the highest number (1-5) rating that a certain reviewer gave. So if reviewer #1 gave two 5's out, it needs to show each movie number that was rated 5.
I'm getting: invalid conversion from 'void (*) (int (*) [6])' to 'int' for this line:
highest = initialRatings[reviewer - 1][0];
(initialRatings[][] is my 2D array)
Also: invalid types 'int[int]' for array subscript for these two lines:
if(initialRatings[reviewer - 1][NUM_MOVIES] > highest[count])
{
highest[count] = initialRatings[reviewer - 1][count];
The last error I get is: C++ forbidds comparison between pointer and integer on the lines:
if(initialRatings[reviewer - 1][count] == highest)
I tried testing this same method with a 1D array and it doesn't give me any errors.
"highest = array1D[0];"
I know this is probably going to go into pointer examples, but if there's any way to avoid using/manipulating pointers that would be great. Since we don't cover those till next semester, and that means there should be a way to do this w/o pointers. Also I can't use vectors, even though that would make it easier.
My best understanding at why this doesn't work for a 2D is that it's trying to convert/assign a memory location to a single integer which can't happen, right? A lot of google examples show them doing exactly what I've done, so I'm not sure what's going on.
here's my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
void showReviewersHighestRating(int [][NUM_MOVIES],const int movieID[NUM_MOVIES])
{
int reviewer = 0, highestCounter = 0, highest = 0;
cout << "Enter a reviewer number (1-4), to find the Movie they rated the highest:\n";
// use NUM_REVIEWERS for "4"
cin >> reviewer;
// include validation for alpha input
while(reviewer < 1 || reviewer > NUM_REVIEWERS)
{
cout << "That is an invalid reviewer number.\n";
cout << "Enter a reviewer number (1-4), to find the Movie they rated the highest: ";
cin >> reviewer;
}
cout << "Reviewer#" << reviewer << "rated Movie#";
highest = initialRatings[reviewer - 1][0];
for(int count = 1; count < NUM_MOVIES; count++)
{
if(initialRatings[reviewer - 1][NUM_MOVIES] > highest[count])
{
highest[count] = initialRatings[reviewer - 1][count];
}
}
for(int count = 0; count < NUM_MOVIES; count++)
{
if(initialRatings[reviewer - 1][count] == highest)
{
highestCounter++;
}
}
for(int count = 0; count < NUM_MOVIES; count++)
{
if(initialRatings[reviewer - 1][count] == highest)
{
cout << movieID[count];
highestCounter--;
if(highestCounter == 1)
{
cout << " and ";
}
else if(highestCounter > 1)
{
cout << ", ";
}
else if(highestCounter == 0)
{
cout << " as the highest.\n";
cout << "\n";
}
}
}
}
|