2 Dimensional Arrays & Addition

Hi,

I'm meant to write a nested for loop to add 5 to each element of this array, here's my code so far, but I keep getting the error: incompatible types in assignment of 'int' to 'int [4]'|

Any advice?

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
#include <iostream>
using namespace std;

int main()
{
    const int NUMROWS = 3;
    const int NUMCOLS = 4;
    int val[NUMROWS][NUMCOLS] = {{8,16,9,52},
                                {3,15,27,6},
                                {14,25,2,10}};


      for (int row = 0;row < 3;row++)
    {
        for(int column = 0;column < 4;column++)
        {
            cout << val[row][column] << endl;
        }
        cout << endl;
    }

    for (int r = 0;r<3;r++)
    {
        val[r] = r + 5;
        for(int c = 0;c<4;c++)
        {
           val[c]= c + 5;
        }
    }


          for (int row = 0;row < 3;row+5)
    {
        for(int column = 0;column < 4;column+5)
        {
            cout << val[row][column] << endl;
        }
        cout << endl;
    }

    return 0;
}
add 5 to each element

If that is your goal, then what do lines 24 and 27 do?

The compiler error should point out the line of code, where the error occurs. What do you do at that line?


Note: Isn't there something odd in the second nested loop that prints the value of each element? In the way you increment the loop counters ...
Topic archived. No new replies allowed.