Exercise 12: Checkerboard Pattern Of Asterisks

Date completed: 12/09/2017

Write a program that displays the following checkerboard pattern. Your program must use only three output statements, one of each of the following forms:

  1. cout << "*";
  2. cout << " ";
  3. cout << endl;

The Code: CheckerBoard.cpp

                
/*
 * CheckerBoard.cpp
 *
 */
/*
 * This application displays a checker board pattern using Asterisks.
 * But only three output statements are allowed.
 */
#include <iostream>    // Allows program to output data to the screen.

using namespace std;

// The function main() begins program execution.
int main() {
    int outerLoopCount = 8;
    int innerLoopCount = 8;

    while(outerLoopCount != 0){
    
        while(innerLoopCount != 0){
            cout << "* ";
            innerLoopCount--;
        }
        cout << endl;

        if(outerLoopCount % 2 == 0){
            cout << " ";
        }

        innerLoopCount = 8;
        outerLoopCount--;
    }
  
} // end of function main

            

Some screen prints

Description Screen Print Out
The output as seen in Eclipse. cpp_s03_ex12 image