I have got this four for-statements in a program of mine:
I have got the random numbers between 0 and 8 and field has the size [8][8].Code:for (int i = a + 1, j = b + 1; i < 8 || j < 8; i++, j++) { field[i][j] = -1; filled++; cout << i << ' ' << j << endl; // Just to see what happens } for (int i = a + 1, j = b - 1; i < 8 || j >= 0; i++, j++) { field[i][j] = -1; filled++; } for (int i = a - 1, j = b + 1; i >= 0 || j < 8; i++, j++) { field[i][j] = -1; filled++; } for (int i = a - 1, j = b - 1; i >= 0 || j >= 0; i++, j++) { field[i][j] = -1; filled++; }
I wanted to set from the random numbers a and b the diagonals to -1. I handle the two diagonals in two ways: first diagonal down and then up.
The problem is that after compiling and running the program crashes. After putting a cout statement in the first for-loop I saw what went wrong. This is the output:
I wasn't expecting that i or j would be greater then eight. Can someone tell me what I am doing wrong.Code:2 5 3 6 4 7 5 8 6 9 7 10
I am using BCC5.5.



LinkBack URL
About LinkBacks



CornedBee