Thread: Checkerboard

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    Checkerboard

    I've created a bigger checkerboard.
    Still missing the numbers on the side 1-8. I have an idea how to do it but i thought i asked if somebody had a simpler solution.
    I thought of using int i=1; incrementing it until 8 and put in the VERTICAL LINES section
    Code:
      if(x==41)       cout<<(char)179 << "\n" << "    " ;
    after every 5th or something line.

    Code:
    #include <cstdio>
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    COORD NewSBSize = GetLargestConsoleWindowSize(h);
    SMALL_RECT DisplayArea = {0, 0, 0, 0};
    
    int main()
    {
        SetConsoleScreenBufferSize(h, NewSBSize);  // FULLSCREEN
        DisplayArea.Right = NewSBSize.X - 1;
        DisplayArea.Bottom = NewSBSize.Y - 1;
        GetConsoleScreenBufferInfo(h, &csbiInfo);
        
        cout<< "        A         B        C        D        E        F       G        H "<<endl<<endl;
        for(int y=0; y<42; y++)
            for(int x=0; x<42; x++)
               
               if(y==1)                          // FIRST LINE OF CHECKERBOARD
                    if(x==0)   cout<< "    " ;
                    else if(x==1)   putchar(218);
                    else if(x==41)  cout<<(char)191 << "\n" <<"    " ;
                    else if(x%5==1) putchar(194);
                    else            cout<<(char)196<<(char)196;
               
               else if(y%5==1 && 37>y)          // HORIZONTAL  LINES
                    if(x==0)        cout<< "";
                    else if(x==1)   putchar(195);
                    else if(x==41)  cout<<(char)180<< "\n" <<"    " ;
                    else if(x%5==1) putchar(197);
                    else            cout<<(char)196<<(char)196;    //horizontal lines
                                                                                 
               else if(y==41)                  // LAST LINE OF CHECKERBOARD
                    if(x==0)        cout<< "";
                    else if(x==1)   putchar(192); 
                    else if(x==41)  cout<<(char)217<< "\n" << "   " ;
                    else if(x%5==1) putchar(193);
                    else            cout<<(char)196<<(char)196;
             
               else if(y!=0)                  // VERTICAL LINES
                    if(x==41)       cout<<(char)179 << "\n" << "    " ;
                    else if(x%5==1) cout<<(char)179 <<"        " ;   // vertical lines
                     
        cout<< endl;
        system("pause");
        return 0;
    }
    Last edited by Ducky; 03-16-2009 at 12:10 PM.
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    I chose the ternary operator but it puts out 0s and 1s before every line.
    Could someone tell me why does it do that? Thanks!

    Code:
      
    else if(y!=0)                  // VERTICAL LINES
         if(x==41)       cout<<(char)179 << "\n" << 
                         (y%3==1 && 37>y)? cout<< "   1" : cout<<"    " ; // numbers 1-8 
         else if(x%5==1) cout<<(char)179 <<"        ";
    Ps: ill add the for(; loop for 1-8 later, right now im just testing.
    Last edited by Ducky; 03-17-2009 at 05:51 AM.
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random Checkerboard Help
    By ninety3gd in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2009, 11:11 PM
  2. Checkerboard pattern
    By magnum38 in forum Tech Board
    Replies: 4
    Last Post: 08-17-2006, 02:37 AM