I
I
Ilya2018-11-22 19:02:15
C++ / C#
Ilya, 2018-11-22 19:02:15

How to solve the cycle problem?

Guys, the array is read from the file, then I start the loop and draw a certain figure at a certain value of the array, the problem is that at one moment the y coordinate jumps by 300 units. Here is the program code

#define n 12
#define m 8
void game() {
  cleardevice;
  initwindow(1200, 800);
  int a[n][m];
  int pole[n][m];
  int xp, yp;
  int rebel[5], droid[5], Buf[2], score = 0;
   key = 0;
  FILE *f;
  f = fopen("Map 1.txt", "r");
  for (int i = 0; i < m-1; i++)
  {
    for (int j = 0; j < n; j++)
    {
      fscanf(f, "%d", &pole[i][j]);
      printf("%d ", pole[i][j]);
      
    }
    printf("\n");

  }
  int x = 0, y = 0;
  for (int i = 0; i < m; i++)
  {
    x = 0;
    
    for (int j = 0; j < n; j++)
    {

      switch (pole[i][j])
      {
      case 1: brick(x, y, DarkGray); printf("%d %d\n", x, y);
      case 0:;


      }
      x += 100;

    }
    y += 100;
    
  }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-11-22
@BeSnoMo

pole[n][m];
maybe pole[m][n]; considering how cycles are constructed?
in there is garbage pole[...][n > 8] the same initpole[m-1][...]

for(int i = 0; i < m-1; i++)
{
  for (int j = 0; j < n; j++)
  {
    fscanf(f, "%d", &pole[i][j]);
    printf("%d ", pole[i][j]);	
  }
  printf("\n");
}

reading
for (int i = 0; i < m; i++)//??? i < m-1 ???
{
  x = 0;
  for (int j = 0; j < n; j++)
  {
    switch (pole[i][j])
    {
      case 1: 
        brick(x, y, DarkGray); 
        printf("%d %d\n", x, y);
        break; //???
      case 0:;
      //...
    }
    x += 100;
  }
  y += 100;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question