468,503 Members | 2,039 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,503 developers. It's quick & easy.

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 6204
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

Post your reply

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

Similar topics

1 post views Thread by Varun Hiremath | last post: by
13 posts views Thread by asif929 | last post: by
6 posts views Thread by asif929 | last post: by
63 posts views Thread by biyubi | last post: by
2 posts views Thread by CoreyWhite | last post: by
2 posts views Thread by shatranjchess | last post: by
10 posts views Thread by sam_cit | last post: by
7 posts views Thread by needhelp20 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.