By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Creating A Chessboard Program in C++

P: 11
I have the idea to create the program but I need help in finishing it. My task is to write a program that prints out a chessboard using only asterisks. I have to use multiple nested loops with nested conditional statements inside. The output should look like a chessboard as follows: The pattern is not coming out as I want but I guess y'all know what a chessboard look like

* * * * *
* * * * *
* * * * *



* * * * *
* * * * *
* * * * *


int main()
{
for (int rowloop = 0; rowloop < 4; rowloop++)
{
for (int row = 0; row < 3; row++)
{
for (int column = 0; column < 5; column++)
cout << "*";
cout << endl;
}
cout << endl << endl;
}
return 0;
}

I want to have a variable for the box that way when I set up the row and column if it is odd it starts doing the pattern from the first location and if not it indent in like the second row in the example and print the pattern. I appreciate any help that I can get.
Nov 5 '06 #1
Share this Question
Share on Google+
4 Replies


vninja
P: 40
i tried approaching this challenge a different way. first off i made this program write one line of the whole board x number times then made it rpt a couple of time (pardon the poor writing but its 5 in the morning and i'm dead tired (working) trying to get things to makes sense)

here is my program for creating the board. personally i would have used arrays and functions but this is taking off of what you had originally.



#include<iostream>
using namespace std;

int main()
{
int count = 0; // number for changing which row gets printed to screen in what
// pattern, change this to one to invert the pattern
for(int row = 0;row<6;row++) // number of rows in a chess board (might want to
{ // change that 6 to whatever you need)
if(count == 0)
{
for(int sqr=0;sqr<4;sqr++) // square size row wise how many * will be under
{ // each other
for(int col=0;col<6;col++)// <-- number of collumns in chess board divided by
{ // 2 (dark and light)
cout << " *****"; //<-- the output. if your square are going to be
} // squares make sure the num of * and spaces are
cout<<endl; // equivilant to the int number of variable sqr ^ above
}
}
else // when count switches this changes the output to the following
{
for(int sqr=0;sqr<4;sqr++)
{
for(int col=0;col<6;col++)
{
cout << "***** ";
}
cout<<endl;
}
}
count++;
if(count == 2)
count = 0; // keeps count 0 or 1
}
system("pause");

return 0;
}

sorry if this is comments are kind of long but i don't know what level of C++ you understand.
Nov 6 '06 #2

vninja
P: 40
here is my output:

***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
Nov 6 '06 #3

vninja
P: 40
Here is my output (let me try again)
***** *****
***** *****
***** *****
***** *****
***** *****
***** *****
***** *****
***** *****
***** *****
***** *****
***** *****
***** *****
looks good on my post and on my screen but don't know if posting will cause formatting errors
Nov 6 '06 #4

P: 11
Thank you so much for your response. I will try and run the program again tonight to see what happen and let you know.
Nov 6 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.