Chess Board Program using While statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Botang
    New Member
    • Nov 2007
    • 8

    #1

    Chess Board Program using While statements

    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..
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    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.

    Comment

    • Botang
      New Member
      • Nov 2007
      • 8

      #3
      Code:
      count = 1;
      while (count <=5)
      {
      cout << whiteRow << endl;
      count ++;
      }
      
       innercount = 1;
      while (innercount <=5)
      {
      cout << blackRow << endl;
      innercount ++;
      }
      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)

      Comment

      • RRick
        Recognized Expert Contributor
        • Feb 2007
        • 463

        #4
        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.

        Comment

        • Botang
          New Member
          • Nov 2007
          • 8

          #5
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********
          ******** ******** ******** ********

          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?

          Comment

          • Botang
            New Member
            • Nov 2007
            • 8

            #6
            Code:
                 
                    ********        ********        ********        ********
                    ********        ********        ********        ********
                    ********        ********        ********        ********
                    ********        ********        ********        ********
                    ********        ********        ********        ********
            ********        ********        ********        ********
            ********        ********        ********        ********
            ********        ********        ********        ********
            ********        ********        ********        ********
            ********        ********        ********        ********
            - correction

            Comment

            • Botang
              New Member
              • Nov 2007
              • 8

              #7
              Code:
               ********        ********        ********        ********
                          ********        ********        ********        ********
                          ********        ********        ********        ********
                          ********        ********        ********        ********
                          ********        ********        ********        ********
                 ********        ********        ********        ********
                 ********        ********        ********        ********
                 ********        ********        ********        ********
                 ********        ********        ********        ********
                 ********        ********        ********        ********
              ~ another correction
              ~ getting used to this program

              Comment

              • Botang
                New Member
                • Nov 2007
                • 8

                #8
                The lines are supposed to line up > like a chessboard
                They line up properly in the program but on this screen... reply thingy

                Comment

                • Botang
                  New Member
                  • Nov 2007
                  • 8

                  #9
                  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.

                  Comment

                  • Ganon11
                    Recognized Expert Specialist
                    • Oct 2006
                    • 3651

                    #10
                    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.

                    Comment

                    • Botang
                      New Member
                      • Nov 2007
                      • 8

                      #11
                      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.

                      Comment

                      • Ganon11
                        Recognized Expert Specialist
                        • Oct 2006
                        • 3651

                        #12
                        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.

                        Comment

                        Working...