473,242 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

Chess Board Program using While statements

8
Create a chessboard program by using while statements and you can only use TWO cout statments.. (using C++)
One cout is cout<< whiteRow << endl;
THe other cout is cout <<blackRow << endl;

whiteRow = WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK;

blackRow = BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE;

The program has the dimensions of 8 blocks of 5 lines that look alike ??
SO far this is what I have:

#include <iostream>
#include <string>
using namespace std;

const string BLACK = "********";
const string WHITE = " ";

int main ()
{

whiteRow = WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK;

blackRow = BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE;

while (count <= 5)
cout << whiteRow << endl;
count ++
innercount = 0
while (innercount <5)
cout << blackRow << endl;
innercount++



~~~ Could really use the help THANKYOU

Please Help..
Nov 16 '07 #1
11 6769
Ganon11
3,652 Expert 2GB
Please read our Posting Guidelines. You haven't really given us an idea of what you're having trouble with, you didn't use [code] tags, and you posted in the wrong section. Please make sure you read and understand the above guidelines before posting again. Thank you.
Nov 16 '07 #2
Botang
8
Expand|Select|Wrap|Line Numbers
  1. count = 1;
  2. while (count <=5)
  3. {
  4. cout << whiteRow << endl;
  5. count ++;
  6. }
  7.  
  8.  innercount = 1;
  9. while (innercount <=5)
  10. {
  11. cout << blackRow << endl;
  12. innercount ++;
  13. }
  14.  
I have modified the code and changed it to this. When we compile the program it outputs two blocks of asterisks. I need it to output six more blocks.
How do we get it to output 6 more blocks...
(Also i don't understand where else to post this or how to)
Nov 16 '07 #3
RRick
463 Expert 256MB
When you repost, show us some output of the chessboard.

A couple of questions. Why count == 5? I thought chess boards had 8 rows.

Your white string is null. When you concate white with black, you'll only see black. If all you are doing is printing out strings, I can see this being done with a single while loop.
Nov 16 '07 #4
Botang
8
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********
******** ******** ******** ********

This is what the output looks like. I need it to do this 6 more times.
I have while (count <=5) because the const white is = " " (= to 8 blanks)
a const black is = "********" (=to 8 asterisks)....
and a white row = WHITE + BLACK + WHITE + BLACK
If you can't manipulate what I have.. How would you make it into a single while statment?
Nov 16 '07 #5
Botang
8
Expand|Select|Wrap|Line Numbers
  1.  
  2.         ********        ********        ********        ********
  3.         ********        ********        ********        ********
  4.         ********        ********        ********        ********
  5.         ********        ********        ********        ********
  6.         ********        ********        ********        ********
  7. ********        ********        ********        ********
  8. ********        ********        ********        ********
  9. ********        ********        ********        ********
  10. ********        ********        ********        ********
  11. ********        ********        ********        ********
  12.  
- correction
Nov 16 '07 #6
Botang
8
Expand|Select|Wrap|Line Numbers
  1.  ********        ********        ********        ********
  2.             ********        ********        ********        ********
  3.             ********        ********        ********        ********
  4.             ********        ********        ********        ********
  5.             ********        ********        ********        ********
  6.    ********        ********        ********        ********
  7.    ********        ********        ********        ********
  8.    ********        ********        ********        ********
  9.    ********        ********        ********        ********
  10.    ********        ********        ********        ******** 
~ another correction
~ getting used to this program
Nov 16 '07 #7
Botang
8
The lines are supposed to line up > like a chessboard
They line up properly in the program but on this screen... reply thingy
Nov 16 '07 #8
Botang
8
How would you change the code so that it prints out 8 blocks of chessboard rows using only while statement?

Please help... I am not quite understanding and I am under deadline.
Nov 16 '07 #9
Ganon11
3,652 Expert 2GB
Why is your WHITE variable only 1 space, but your BLACK variable is 8 asterisks? Maybe you should make them the same length for printing - I found 2 symbols was a good length when I made a simple chess program a year ago.

Finally, you just need to alternate printing white and black rows. You can do this either by using a variable to determine whether a white or black row should be printed, then put this in a loop executing 8 times, or write a loop to output a white row, newline, a black row, and another newline, then make this loop execute 4 times.
Nov 16 '07 #10
Botang
8
In the program I have created, the strings are of both the same length. I don't know why it showed up as one blank. I am having difficulty understanding this concept. Could someone please show me an example of a while statement that would execute 8 blocks of asterisks and blanks...
I would very much appreciate any input.
Nov 17 '07 #11
Ganon11
3,652 Expert 2GB
Do you know how to make a loop?

Do you know how to put statements into a loop?

Do you know how to know how many times your loop will run?

If so, then you know everything you need to complete this program. There is no way we can do what you are asking for without violating the Posting Guidelines.
Nov 17 '07 #12

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

Similar topics

1
by: Varun Hiremath | last post by:
Hello, I have written a chess client using python which is a graphic interface to play chess. It is at present a two player version, players move their peices by clicking two squares on the board...
13
by: asif929 | last post by:
I have been trying to create this chess program from many hours and still couldn't figure out how to complete it. After consume all these efforts i come to this google groups for the first time for...
6
by: asif929 | last post by:
I have been trying to create this chess program from many hours and still couldn't figure out how to complete it. After consume all these efforts i come here for the first time for help. i would...
63
by: biyubi | last post by:
Hi, a year ago I won the 2005 Best Game categoryof the International Obfuscated C Code Contestwith a chess program. http://www.ioccc.org/whowon2005.html...
2
by: CoreyWhite | last post by:
When playing games, perhaps the most simple is tic-tac-toe. The game has two simple strategies, one is defensive and the other offensive. It is not hard at first to learn how to tie games when...
2
by: shatranjchess | last post by:
I'm releasing a new python chess module called shatranj. You can get it from www.employees.org/~stannous/shatranj until I move the project to sourceforge or some other place. It's a text based...
10
by: sam_cit | last post by:
Hi Everyone, I'm working on developing a chess game and i decided to use c++ for its object oriented approach. I have a bass class unit and is inherited to distinct number of units (like king,...
7
by: needhelp20 | last post by:
how to make a appropriate move for each pawns? I knew that I should used some HashMap or classes for every pawn,but I don't know how to implement in code... Here is my code: import java.awt.*;...
3
by: Untitled123 | last post by:
Hey guys!! I am Planning on Creating a Computer vs. User Chess game involving Artificial Intelligence... by just using TURBO C++ This is NOT impossible!! Please understand that my seniors...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.