# Thread: 2d arrays: H e l p!

1. ## 2d arrays: H e l p!

hi all,
i am having difficulty understanding how to use 2d arrays in any of my functions...
I know how to find the max[] for any array, but when the arr[][] comes into the picture i'm getting messed up!

here's what my max function is: (my array has 4 rows, 6 cols) and the content has been inputted and printed by previous functions.
I'm not sure my function or call are correct either..
for some reason the logic is passing me, hope someone can explain.thanks, Michele

Code:
```//prototype
int Maxsearch(int arr2d[][cols], int SIZE);

//call
Maxsearch(arr2d, SIZE);

//Part3 : Function definition: Largest Int & Address
int Maxsearch(int arr2d[][cols], int MAX){

outfile << "\n\n";
outfile<<setw(60)<< "Part 3 - Largest Integer & Address:" << "\n\n" << endl;
outfile<< setw(30) << endl;
MAX = arr2d[0][6];
int MAXi = 0;
for ( int i = 0; i < MAX; i++ ){
if (arr2d[i][6] > MAX){
MAX = arr2d[i][6];
MAXi = i;
}

outfile<< MAX << setw(4) << MAXi << endl;
}
return 0;
}```

2. Two things, if cols isn't a const global variable, I don't think this will compile. If it isn't you need to do this in the definition:
Code:
```//Part3 : Function definition: Largest Int & Address
int Maxsearch(int arr2d[][6], int MAX)```
Second, if I'm to understand you correctly, then are you looking for the greatest number out of the entire array, or just one column of the array? If you want the whole thing, you need two nested for loops like so:
Code:
```for (int x=0; x<rowsize; x++)
{
for (int y=0; y<colsize; y++)
{
if (arr2d[x][y]>max)
{
max=arr2d[x][y];
MAXx=x;
MAXy=y;
}
}
}```
If you just want to check the 6th column, then your code for finding the max looks fine to me.

3. ## still

am still needing help,
i am so not getting this...
could you explain what your nested loop is doing?
and also if my code for just checking on row is okay why am I not getting anything close to an answer?
(I do have a const int cols global)
Thanks Michele
very frustrated newcomer

4. ## more ?

i don't get what you loop tells me...
I already know what that max rows and cols are they are const.
I want to know what the largest integer stored in the array and it's location (as an prdered pair).
i don't see it..and i feel so stupid.
M

5. could you explain what your nested loop is doing?
It traverses ("checks all elements") the array. The max variable contains the max value found in the array and MAXx and MAXy stores the "cordinates" for the max variable.

PJYelton forget´t to assign max to the first element in the array
Code:
```max = arr2d[0][0];
int MAXx, MAXy;
//Implement PJYelton´s code
return arr2d[MAXx][MAXy];```
Add this to the function Maxsearch and it should work