Checkers board

This is a discussion on Checkers board within the C Programming forums, part of the General Programming Boards category; I'm looking to make a checkers board.. A typical square of checkers board looks like PHP Code: +-----+ |     | |     | ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    113

    Checkers board

    I'm looking to make a checkers board..
    A typical square of checkers board looks like
    PHP Code:
    +-----+
    |     |
    |     |
    |     |
    +-----+ 
    my point it is, how do I print the board with rows and columns taken as input.. where should I start and how do I proceed

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    How about a loop which prints "+-----" a number of times.
    And a loop which prints "| " a number of times.

    Then loops calling those loops.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    113
    I even thought about it but the problem comes when I want something like this...
    PHP Code:
    +-----+-----+
    |     |     |
    |     |     |
    |     |     |
    +-----+-----+ 
    as printf() takes \n by default... so, how would I handle this.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    I would suggest you spend the next day thinking about how this works then.
    Code:
    #include <stdio.h>
    
    void foo ( void ) {
      for ( int i = 0 ; i < 8 ; i++ ) printf("+----");
      printf("+\n");
      for ( int i = 0 ; i < 3 ; i++ ) {
        for ( int j = 0 ; j < 8 ; j++ ) printf("|    ");
        printf("|\n");
      }
    }
    
    int main()
    {
      for ( int i = 0 ; i < 8 ; i++ ) foo();
      return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checkers!!
    By salmanriaz in forum Game Programming
    Replies: 0
    Last Post: 04-20-2009, 11:02 AM
  2. C++ Checkers Game
    By SnS CEO in forum C++ Programming
    Replies: 9
    Last Post: 09-07-2005, 01:21 AM
  3. The Secret to Checkers...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 07-19-2002, 07:51 AM
  4. Help with Checkers
    By Luke2525 in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2002, 05:46 PM
  5. Checkers/Tic-Tac-Toe
    By Dummies102 in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2002, 05:07 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21