### Problem with 2D array

Hello all. So I am working on a homework assignment where we are asked:

"You are given a 6x8 (6 rows, 8 columns) array of integers , x , already initialized and three integer variables : max , i and j . Write the necessary code so that max will have the largest value in the array x ."

This is the code I have and it is telling me that max is not being assigned the correct value, and I have gone over this code a few times and can't see why it wouldn't be. Any help without directly fixing the code would be great, as I'd like just get a hint as to where I messed up x)

Thanks guys

 ``12345678`` ``````max = 0; for(i = 0; i < 6; i++){ for(j = 0; j < 8; j++){ if(max < x[i][j]) max = x[i][j]; } j = 0; }``````

Last edited on
You don't need: `j = 0;` after inner for loop
are type integer your max variable?
 This is the code I have and it is telling me that max is not being assigned the correct value

compiler error?
Last edited on
Wouldn't you need j = 0 to reset the variable so the for loop triggers again and goes through the columns?

Yeah max is an int type. Essentially they already have max, i and j initialized. I'm using codelab

It doesn't say that there's a compiler error, it's just telling me that max is not the correct value. usually with compiler error's it'd tell me where as the Codelab site has a C++ compiler within it
always that your inner loop -`for(j=0;j<8;j++)`- starts,j it's initialized to 0;

hint: initialize max with your first array value i.e. x[0][0];

Codelab? i don't know this site!

Last edited on
Topic archived. No new replies allowed.