2D array problem assigning to an int variable

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";
            }
        }
    }
}
Line 1: variable name is missing on the first argument.

Line 3: highest is a simple int. Line 21: You're trying to index a simple int. Why are you indexing it?

After removing the index from highest, I don't get any other errors.




My book says the first range of the array can be left out, it only needs the column (the last range of an array) to work, but I made the change anyway.

void showReviewersHighestRating(int [NUM_REVIEWERS][NUM_MOVIES],const int movieID[NUM_MOVIES])

That's true, not sure why I had indexed highest.

That's weird you aren't getting the invalid conversion from void int to int (after the changes I'm still getting this), But it's also weird I've seen several examples online doing this same thing and it compiles.
Yes, the first dimension can be omitted. That is not what I was saying. You're missing the variable name. Variable name is required.
1
2
3
void showReviewersHighestRating(int missing_variable_name[NUM_REVIEWERS]
....................................^^^^^^^^^^^^^^^^^^^^^
[NUM_MOVIES],const int movieID[NUM_MOVIES])
Last edited on
Oh dammit, I must've deleted it. I had it in all of my other function definitions. Thank you!
Declaration – Syntax: data_type[][] array_name = new data_type[x][y]; For example: int[][] arr = new int[10][20];
Initialization – Syntax: array_name[row_index][column_index] = value; For example: arr[0][0] = 1;
Declaration – Syntax: data_type[][] array_name = new data_type[x][y]; For example: int[][] arr = new int[10][20];


Not in standard C++.

error C2760: syntax error: unexpected token ']', expected 'id-expression'
Last edited on
Topic archived. No new replies allowed.