for loop - Connect four game board in C -
i writing program allows user play game connect 4 against computer. having trouble printing out correct dimensions board. tried using nested loops, output little off. here part of code:
#include <stdio.h> #define board_size_vert 6 #define board_size_horiz 7 void display_board(int board[] [board_size_vert]); int main () { int board[board_size_horiz][board_size_vert] = {{0}}; display_board(board); return 0; } void display_board(int board[] [board_size_vert]) { int i,j; (i=0; i<board_size_horiz; i++) { printf ("+---+---+---+---+---+---+---+"); printf ("\n"); (j=0; j<board_size_vert; j++) printf ("| "); printf("\n"); } }
this output:
+---+---+---+---+---+---+---+ | | | | | | +---+---+---+---+---+---+---+ | | | | | | +---+---+---+---+---+---+---+ | | | | | | +---+---+---+---+---+---+---+ | | | | | | +---+---+---+---+---+---+---+ | | | | | | +---+---+---+---+---+---+---+ | | | | | | +---+---+---+---+---+---+---+ | | | | | |
and want like:
+---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+ | | | | | | | | +---+---+---+---+---+---+---+
void display_board(int board[] [board_size_vert]){ int i,j; (i=0; i<board_size_vert; i++) { printf ("+"); (j=0; j<board_size_horiz; j++) printf("---+"); printf ("\n"); printf ("|"); (j=0; j<board_size_horiz; j++) printf(" |"); printf ("\n"); } printf ("+"); (j=0; j<board_size_horiz; j++) printf("---+"); printf ("\n"); }
Comments
Post a Comment