473,471 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating A Chessboard Program in C++

11 New Member
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
4 9293
vninja
40 New Member
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
40 New Member
here is my output:

***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
***** ***** ***** ***** ***** *****
Nov 6 '06 #3
vninja
40 New Member
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
punkybrewster
11 New Member
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

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

Similar topics

1
by: asdasd | last post by:
Hello there, I'm hoping someone might be able to help me out. Its been awhile since I've programmed in visual basic (and roughly at that)... I want to create a program that will allow me to...
2
by: Paul | last post by:
I am creating a Program for college, in which the Program will read a Folder and create a HTML page from the pictures that are storrd in that folder. . What would be the best way to do...
0
by: Paul | last post by:
I am creating a Program for college, in which the Program will read a Folder and create a HTML page from the pictures that are storrd in that folder. .. What would be the best way to do it in VB...
0
by: Brian Mitchell | last post by:
Are there any good sites out there that show you how to make a modular program? For instance, I would like to create a program that accepts a snap-in. A user would download the main program and...
3
by: Erik Foreman | last post by:
I am using a folderbrowserdialog object to prowse to a folder then once in that folder I am going to have my program rename all of the files in that folder. I know the rename funchtion but I am not...
4
by: recruitor2001 | last post by:
Objective: To create a program that will allow the end user to input a number in terms of minutes and then click start. Once start has been selected a timer will start counting down from the the...
1
by: satish100 | last post by:
how can i write a program for making the plain chessboard in PHP
2
by: hiimnath | last post by:
Hello all, i'm new to vb.net coding and programming and i'm making a program for my 4 year old brother that he has to type words and goes to the next level etc. so i added a new item ( one item...
8
by: pazn16 | last post by:
I'm having trouble creating a program for this. I'am fairly new to C# so I don't really know exactly what to do. Create a C# program which prompts to the user to enter some dollar and cent amount....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.