can't assign 2d array? Idk why

So I am pretty sure what I am doing is right but it keeps giving me an error so idk if I a missing a header? or I am doing it wrong and thinking its right. So here is my code. This is the error i get
||In function 'void getRatings(int (*)[6])':|
|58|warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x||58|error: cannot convert '<brace-enclosed initializer list>' to 'int' in assignment|
||=== Build finished: 1 errors, 1 warnings ===|


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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <cstdlib>
using namespace std;

const int NUM_REVIEWERS = 4;   //Number of rows in reviews array
const int NUM_MOVIES = 6;	//Number of columns in reviews array


void displayRatings(int [][NUM_MOVIES]);
void getRatings(int [][NUM_MOVIES]);


int main()
{
 // Variable declarations
int reviews[NUM_REVIEWERS][NUM_MOVIES]={0};  // Ratings for reviewers
int choice;


getRatings(reviews);
do
{
    cout<<"---------------------------------------------------"<<endl;
    cout<<"2-D ARRAY PROCESSING MENU OPTIONS"<<endl;
    cout<<"---------------------------------------------------"<<endl;
    cout<<"1. Display current movie ratings"<<endl;
    cout<<"2. Show the average rating for each movie."<<endl;
    cout<<"3. Show a reviewers highest rated movie. (enter reviewer# 1-4)"<<endl;
    cout<<"4. Show a movies lowest rating. (enter movie# 100-105)"<<endl;
    cout<<"5. Quit program"<<endl;

    cout<<endl<<"Enter your choice:";
    cin>>choice;

    switch (choice)
    {
        case 1:
        displayRatings(reviews);
        break;
        case 2:
        break;
        case 3:
        break;
        case 4:
        break;
        case 5:
        break;


    }
}while(choice!=5);

 return 0;
}

void getRatings(int reviews[][NUM_MOVIES])
{
    reviews[NUM_REVIEWERS][NUM_MOVIES]={{3,1,5,2,1,5},{4,2,1,4,1,4},{3,1,2,4,4,1},{5,1,4,2,4,2}};
}


void displayRatings(int reviews[][NUM_MOVIES])
{
    for(int rowCnt = 0; rowCnt < NUM_REVIEWERS; rowCnt++)
    {
        for(int colCnt = 0; colCnt < NUM_MOVIES; colCnt++)
		{
		    cout<<reviews[rowCnt][colCnt]<<" ";
		}
		cout << endl;
	}
}

Last edited on
You can't assign values to array elements using brackets, unless you do it as initialization. Line 16 is correct because you just created the array and you are initilizing it. in getRatings() you're assigning a new value and that's forbidden, you have to use a loop or insert them manually

C++11 introduced support to initiliaze std containers using brackets, but I don't know if it extends arrays capabilities too
Can i insert them manually one by one?( like reviews[1][1]= 3) or do i have to have the user do it?
You can insert them manually but it's not really smart. Why don't you just put the initializer list in line 16?
Not really sure my teacher gave us a sample outline with and I was following his functions even though he said we could do it however we want I think the instructions state you make use the follow outline bellow or create your own
Topic archived. No new replies allowed.