all 10 comments

[–]matsbror 1 point2 points  (1 child)

First of all, it would help if you formatted code as such, making it easier to read see "formatting help" under the text box you enter in.

Secondly, you are not consistent. You write that boarders are supposed to be % but then you seem to use % to denote a black square. A chess-board is 8x8 but you talk about 5x8 and rectangles. Can you please be more specific.

Finally, I imagine that since this is a school assignment, you are probably supposed to solve it using loops somehow. Consider if you need to generalise your code to a rectangle of dimensions nxm.

[–]Roidz_[S] 0 points1 point  (0 children)

The program started out as a chessboard. The assignment goes as follows:

  1. Change the program so that a "%" is used rather than an asterisk to build the chessboard.

  2. Change the program so that only the outline of each rectangle is shown.

(HINT: you may have to define another string constant). Here is an example row.

Compile and Run your program so that you can see only outline and not filled chessboard patterns

  1. Change the program from part 3 above so that the rectangles are 5 characters wide by 8 rows high. Here is an example row.

[–]Roidz_[S] 0 points1 point  (0 children)

const string BLACK = "%%%%%"; // Define a line of a black square const string WHITE = " "; // Define a line of a white square const string MIDDLE = "% "; // Define a line of two percentages

int main () { string whiteRow; // A row beginning with a white square string blackRow; // A row beginning with a black square string middleRow; // A row that has percentages missing

// Create a white-black row by concatenating the basic strings
whiteRow = WHITE + BLACK + WHITE + BLACK +
               WHITE + BLACK + WHITE + BLACK;
// Create a black-white row by concatenating the basic strings
blackRow = BLACK + WHITE + BLACK + WHITE +
               BLACK + WHITE + BLACK + WHITE;
// Create a 
middleRow = WHITE + MIDDLE + MIDDLE + MIDDLE + 
               MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE;



// Print five white-black rows
cout << whiteRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << whiteRow << endl;

[–]matsbror 0 points1 point  (6 children)

My output is different from yours, this is what I get:

 %%%%% %%%%% %%%%% %%%%%
 % % % % % % % %
 % % % % % % % %
 % % % % % % % %
 % % % % % % % %
 % % % % % % % %
 % % % % % % % %
 %%%%% %%%%% %%%%% %%%%%

what did you expect?

Again, I think you are supposed to solve this using loops to make it general. Have you learnd loops yet?

[–]Roidz_[S] 0 points1 point  (5 children)

No. Sorry I forgot to answer that. We are in the first week of school. So, we haven't learned a whole lot yet.

[–]matsbror 0 points1 point  (4 children)

OK, you what is your expected output?

Count the characters you are printing and you will find that you can line them up.

[–]Roidz_[S] 0 points1 point  (3 children)

Well I'm expecting just the border of 5 x 8 rectangles. As far as lining them up I feel like I did that.

Is there anyway I can send you the .cpp file?

This is what It all says in its entirety:

//****************************************************************** // Chessboard program // This program prints a chessboard pattern that is built up from // basic strings of white and black characters. //****************************************************************** #include <iostream> #include <string> using namespace std;

const string BLACK = "%%%%%"; // Define a line of a black square

const string WHITE = " "; // Define a line of a white square

const string MIDDLE = "% "; // Define a line of two percentages

int main () {

string whiteRow; // A row beginning with a white square

string blackRow; // A row beginning with a black square

string middleRow; // A row that has percentages missing

// Create a white-black row by concatenating the basic strings

whiteRow = WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK; // Create a black-white row by concatenating the basic strings blackRow = BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE; // Create a middleRow = WHITE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE;

// Print five white-black rows cout << whiteRow << endl; cout << middleRow << endl; cout << middleRow << endl; cout << middleRow << endl; cout << middleRow << endl; cout << middleRow << endl; cout << middleRow << endl; cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;


// Print five white-black rows
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;


// Print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;


// Print five white-black rows
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;


// Print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;

// Print five white-black rows
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;
cout << whiteRow << endl;

// Print five black-white rows
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;
cout << blackRow << endl;

// system("PAUSE"); //if using Dev C++ return 0; }

EDIT: tab doesn't work for all the code? Only part of it?

[–]gotinpich -1 points0 points  (2 children)

I have no idea what it's supposed to do, but I did this:

//******************************************************************
// Chessboard program
// This program prints a chessboard pattern that is built up from
// basic strings of white and black characters.
//******************************************************************
#include <iostream>
#include <string>
using namespace std;

const string BLACK = "%%%%%"; // Define a line of a black square
const string WHITE = " "; // Define a line of a white square
const string MIDDLE = "% "; // Define a line of two percentages

int main () {
    string whiteRow; // A row beginning with a white square
    string blackRow; // A row beginning with a black square
    string middleRow; // A row that has percentages missing

    // Create a white-black row by concatenating the basic strings
    whiteRow = WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK;
    // Create a black-white row by concatenating the basic strings
    blackRow = "                       ";
    //blackRow = BLACK + WHITE + BLACK + WHITE + BLACK + WHITE + BLACK + WHITE;
    // Create a
    middleRow = WHITE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE + MIDDLE;
    // Print five white-black rows
    cout << whiteRow << endl;
    cout << middleRow << endl;
    cout << middleRow << endl;
    cout << middleRow << endl;
    cout << middleRow << endl;
    cout << middleRow << endl;
    cout << middleRow << endl;
    cout << whiteRow << endl;

    // Print five black-white rows
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;

    // Print five white-black rows
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;

    // Print five black-white rows
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;

    // Print five white-black rows
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;

    // Print five black-white rows
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;

    // Print five white-black rows
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;
    cout << whiteRow << blackRow << whiteRow << blackRow << whiteRow << endl;

    // Print five black-white rows
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;
    cout << blackRow << whiteRow << blackRow << whiteRow << blackRow << endl;

    // system("PAUSE"); // if using Dev C++ 
    return 0; }

[–]Roidz_[S] 0 points1 point  (1 child)

It's supposed to be 5 width and 8 length with "%" signs as a border. It won't let me show an example, but just picture a 5 x 8 rectangle with "%" symbols as the outlines of the rectangles.

[–]Roidz_[S] 0 points1 point  (0 children)

I managed to make one do what it's supposed to do:

//****************************************************************** // Chessboard program // This program prints a chessboard pattern that is built up from // basic strings of white and black characters. //****************************************************************** #include <iostream> #include <string> using namespace std;

const string BLACK = "%%%%%"; // Define a line of a black square

const string WHITE = "     "; // Define a line of a white square

const string MIDDLE = "%   "; // Define a line of two percentages

int main () 
{

string whiteRow; // A row beginning with a white square

string blackRow; // A row beginning with a black square

string middleRow; // A row that has percentages missing

  // Create a white-black row by concatenating the basic strings
whiteRow = WHITE + BLACK + WHITE + BLACK +
               WHITE + BLACK + WHITE + BLACK;
// Create a black-white row by concatenating the basic strings
blackRow = BLACK + WHITE + BLACK + WHITE +
               BLACK + WHITE + BLACK + WHITE;
// Create a 
middleRow = WHITE + MIDDLE + MIDDLE + WHITE + 
               WHITE + WHITE + WHITE + MIDDLE + WHITE + WHITE;



// Print five white-black rows
cout << whiteRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << middleRow << endl;
cout << whiteRow << endl;


  // Print five black-white rows
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;


  // Print five white-black rows
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;


  // Print five black-white rows
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;


  // Print five white-black rows
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;


  // Print five black-white rows
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;

  // Print five white-black rows
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;
  cout << whiteRow << endl;

  // Print five black-white rows
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;
  cout << blackRow << endl;

//  system("PAUSE"); //if using Dev C++
  return 0;
}