C++ 2D Array Help

Hello.

I'm trying to reverse the rows in a 2D array. I can not use switch. Here is what I have so far!

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


const unsigned int R_SIZE = 3;
const unsigned int C_SIZE = 5;

void reverseArray(int numArray[][C_SIZE]);

int main()
{
int i, j;
int numArray[R_SIZE][C_SIZE] =
        {
        {1,2,3,4,5},
        {27,14,8,0,0},
        {9,6,18,111,35}
        };


cout << "The numbers before the reverse: "<< endl;
for(int i = 0; i < R_SIZE; i++)
{
 for(int j = 0; j < C_SIZE; j++)
 {
  cout <<" " <<  numArray[i][j] ;
 }
cout << endl;
}



reverseArray(numArray);
cout << "The numbers after the reverse: " << endl;

for(i = 0; i < R_SIZE; i ++)
{
 for(j = 0; j < C_SIZE; j ++)
 {
  cout << " " <<numArray[i][j];
 }
cout << endl;
}

return 0;
}



void reverseArray(int numArray[][C_SIZE])
{
int i, j;
int temp[R_SIZE][C_SIZE];

//NUMBERS BEING REVERSED

for( i = 0; i < R_SIZE; i++)
{
 for(j = 0; j < C_SIZE; j++)
 {
  temp[(R_SIZE - 1) - i][j] = numArray[R_SIZE][C_SIZE];
 }
}
}




When run, they do NOT come out reversed, I have no idea what I am doing and no idea what to do haha, a push in the right direction anyone?
Line 61 is storing elements into a temporary array but the temporary array is never storing anything back into numArray so numArray is never changed...
I GOT IT!!!!!!!! Thanks
Last edited on
Topic archived. No new replies allowed.