# Need immmediate help with program (basic C++ stuff)

This is a discussion on Need immmediate help with program (basic C++ stuff) within the C++ Programming forums, part of the General Programming Boards category; Hello, I've writing a function to find the three largest integers in a 3rd dimensional array which has #0 to ...

1. ## Need immmediate help with program (basic C++ stuff)

Hello,
I've writing a function to find the three largest integers in a 3rd dimensional array which has #0 to 9 stored exclusively. However, I keep getting the same highest # (usually 9) stored in max_store[]. I have tried everything, and I don't know where to go next. If some one could please offer me some help, I'd really appreciate it. I need this asap. Thank you so much.

Code:
```void find_max(int fun[ROW][COL][LAYER]) {

int num, r, c, l, k;
int max=0;
int max_store[3]={-1};

for (num=0; num < 3; num++) {
for (r=0; r < ROW; r++) {
for (c=0; c < COL; c++) {
for (l=0; l < LAYER; l++) {
for (k=0; k < 3; k++) {
if (max < fun[r][c][l] && max_store[k] != max)
max = fun[r][c][l];
}

}

}

}

max_store[num] = max;
max = 0;

}```
Justin

P.S. If you want to look at entire source file, I attached it to this thread.

2. Write a method to check if a number exists in an array.
Then use that here :
Code:
```if (max < fun[r][c][l] && !NumExistsInArray( max_store, 3 ) )
max = fun[r][c][l];```
The error with your code lies in the fact that it never really checks to see if a number has already been chosen.

3. ## Still unable to get to work!

Hi,
I have tried creating a method to check if a number exists in an array but still I am not getting the proper solutions. If someone could please write me that method, I would really appreciate it.

Code:
```int max_store[3]={-1};

bool NumExistsInArray(int max_store[3], const int qt, int fun[ROW][COL][LAYER]) {

for (int r=0; r < ROW; r++) {
for (int c=0; c < COL; c++) {
for (int l=0; l < LAYER; l++) {
for (int m=0; m < qt; m++) {
if (max_store[m] == fun[r][c][l]) {
return true;
}

}

}

}

}
return false;
}

void find_max(int fun[ROW][COL][LAYER]) {

int max=0;
int num;

for (num=0; num < 3; num++) {
for (int r=0; r < ROW; r++) {
for (int c=0; c < COL; c++) {
for (int l=0; l < LAYER; l++) {

if (max < fun[r][c][l] && !NumExistsInArray( max_store, 3, fun ))
max = fun[r][c][l];

}

}

}
max_store[num] = max;
max = 0;

}```
Justin

4. You need to...

Oh! Wait a minute. You needed immediate help. Sorry, I was too late. Never mind.