The following code is meant to simulate and set up a checkers board. It then asks for 2 numbers, and prints out the piece on that square. The first loop in main() runs fine, but the program ends after the loop does. Can anyone explain this please?
Code:
/*
A checkers engine, for future use in programs
by Alex Borland
*/
#include <iostream>
using namespace std;
struct square{
int status;
int xPos;
int yPos;
};
int main(){//The main point of interest is here...
//--------------declare board
square board[12][12];
int dec1 = 0;
int dec2 = 0;
cout << "declaring board" << endl;
for (dec1=0; dec1<13; dec1++){
for (dec2=0; dec2<13; dec2++){
board[dec1][dec2].status = 0;
}
}
//the loop runs, but the program stops after the loop breaks
cout << "board declared" << endl;
//-------------------done declaring board, start placing pieces
board[2][3].status = 1;//starting positions for all black pieces
board[3][2].status = 1;//black pieces are denoted by 1, kings by 2
board[3][4].status = 1;//an empty space has a status of 0;
board[4][3].status = 1;//for our purposes of move restrictions, there is a 2-space border around the outside which all contain status 9 'neutral' pieces to prevent off-board movement
board[5][2].status = 1;
board[5][4].status = 1;
board[6][3].status = 1;
board[7][2].status = 1;
board[7][4].status = 1;
board[8][3].status = 1;
board[9][2].status = 1;
board[9][4].status = 1;
board[2][9].status = 4;//starting positions for all red pieces
board[2][7].status = 4;//squares occupied by a red piece are denoted by a 4, kings are 5
board[3][8].status = 4;
board[4][9].status = 4;
board[4][7].status = 4;
board[5][8].status = 4;
board[6][9].status = 4;
board[6][7].status = 4;
board[7][8].status = 4;
board[8][9].status = 4;
board[8][7].status = 4;
board[9][8].status = 4;
//----------------------------------done setting up board
cout << "board set up" << endl;
int i = 0;
int j = 0;
cout << "select the X poition of the square you want to view" << endl;
cin >> i;
cout << "and the Y position?" << endl;
cin >> j;
cout << board[i][j].status;
return 0;
}