C++ Program to Build Chess Board Pattern With Black and White Words on Command Line

Using this tutorial, You are going to execute the C++ Program to Build Chess Board Pattern With Black and White Words on Command Line successfully without facing any troubles. Let’s start the tutorial.

C++ Program to Build Chess Board Pattern With Black and White Words on Command Line

C++ Program to Build Chess Board Pattern With Black and White Words on Command Line

Program Code

#include <iostream>
using namespace std;

int main()
{
    int i, j, rows;
    string b, w, t;
    b = "black";
    w = "white";
    cout << "nn Display checkerboard pattern with the words 'black' and 'white':n";
    cout << "---------------------------------------------------------------------n";
    cout << " Input number of rows: ";
    cin >> rows;
    for (i = 1; i <= rows; i++) 
    {
        for (j = 1; j <= rows; j++) 
        {
            if (j % 2 != 0) 
            {
                cout << b;
                if (j < rows) 
                {
                    cout << "-";
                }
            }
            else if (j % 2 == 0) 
            {
                cout << w;
                if (j < rows) 
                {
                    cout << "-";
                }
            }
        }
        t = b;
        b = w;
        w = t;
        cout << endl;
    }
}

Final Thoughts

I hope this article about “C++ Program to Build Chess Board Pattern With Black and White Words on Command Line” will be beneficial to you. If you have any doubts regarding the concept please contact us via the comment section. Share this article with your friends via social media.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment