#Incrementing neighboring elements in 2D array

21 messages · Page 1 of 1 (latest)

dense scarab
#

For this assignment I have to increment a neighboring element in the 2D array. I'm sure I'm just having a massive brain fart, but I'm confused on how to increment.

for(int i = 0; i < height(); i++)
{
for(int j = 0; j < width(); j++)
{
if(weights[i][j] < 1000000 && weights[i][j] < W_FINISH)
{
weights[i][j] = weights[i][j] = 0;
weights[i][j] = weights[i][j] + 1;
}
}
}

the expected output should be the first image however I am getting the second image

steel lotusBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

dense scarab
#

I know the loop is wrong I am just stuck on what i should do

steel lotusBOT
#

For this assignment I have to increment a neighboring element in the 2D array. I'm sure I'm just having a massive brain fart, but I'm confused on how to increment.

for (int i = 0; i < height(); i++) {
  for (int j = 0; j < width(); j++) {
    if (weights[i][j] < 1000000 && weights[i][j] < W_FINISH) {
      weights[i][j] = weights[i][j] = 0;
      weights[i][j] = weights[i][j] + 1;
    }
  }
}

the expected output should be the first image however I am getting the second image

Izzy
vast estuary
#

weights[i][j] + 1; can only ever evaluate to 1

#

you set it to 0 in the previous statement

dense scarab
#

yeah i kinda figured i fucked up there which i'm trying to fix, but my other thought process is to use a value to add 1 to the element bordering 0 and then continue doing that until i hit an x

#

which i tried differently here

#

!format

steel lotusBOT
dense scarab
#

!format

steel lotusBOT
#
int incrementValue = 2;
for (int i = 0; i < height(); i++) {
  for (int j = 0; j < width(); j++) {
    if (weights[i][j] < 1000000 && weights[i][j] < W_FINISH) {
      if (weights[i][j] < 0) {
        weights[i][j] += incrementValue;
        incrementValue++;
      }
    }
  }
}
Izzy
dense scarab
#

which gives me this instead

#

for more context the base weights are -1 with the "finish line" being 0

vast estuary
#

@dense scarab Is it supposed to be every item is 1 + the value in the previous row?

#

Your code here lacks anything that would make the value based on the row number at all

dense scarab
#

Yeah it is

#

I got it solved

#

!solved