so im trying to build a connect 4 gameboard using charecter arrays and it has to look like this
O | O | O | O
-------------
O | O | O | O
-------------
O | O | O | O
-------------
O | O | O | O
Column: A B C D
so far ive got everything working except for the barriers on the odd numbered lines, it just gives me gibberish for some reason
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
// ----------- Function definitions -------------
void setgameboard(char board[7][12]){
int i,j,k;
for (i=0;i<7;i++){//row loop
if (i==0||i==2||i==4||i==6){ //if row isnt barrier
for (j=0;j<13;j++){//start row that isnt barrier
if(j==0||j==4||j==8||j==12) {board [i][j]='O';} //is open space for token
if(j==1||j==3||j==5||j==7||j==9||j==11){board[i][j]=' ';}//is space
if(j==2||j==6||j==10){board[i][j]='|';}//is divider
} //close if row isnt barrier loop
if (i==1||i==3|| i==5){for (k=0;k<13;k++){board[i][k]='-';}} //if row is barrier
} //close column loop
}//close row loop
}
int main()
{
// -------- Constant declarations --------
// -------- Variable declarations --------
char board[7][12];
int i,j;
//--------Main Program Body----------
cout << "**** ***"<<endl<<endl; //title
setgameboard(board);
for (i=0;i<7;i++){ for (j=0;j<13;j++){cout<<board[i][j];}cout<<endl;}
cout << endl << endl;
system("PAUSE"); // Pause the output window for reading
return 0;
}
is it just something with my print or am i making a mistake with the function? is there an easier way to do this? please help! thanks!