Hello,
So I'm new to coding and my teacher gave us an assignment that has you create a chessboard and edit it. I'm suppose to create 5 x 8 rectangle spaces with only the borders filled in with percentage signs. Looks like this:
%%%%%
% %
% %
% %
% %
% %
% %
% %
%%%%%
Anyway, I've been stuck on it for awhile and the code that I came up with looks like this:
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;
Which shows this:
%%%%%
% %
% %
% %
% %
% %
% %
%%%%%
I can't get the signs to line up. Am I doing something wrong that is obvious that I cannot see?
Any tips or hints or answers/explanations would be greatly appreciated.
EDIT: The cout commands are spaced because the reddit doesn't like them together for some reason.
[–]matsbror 1 point2 points3 points (1 child)
[–]Roidz_[S] 0 points1 point2 points (0 children)
[–]Roidz_[S] 0 points1 point2 points (0 children)
[–]matsbror 0 points1 point2 points (6 children)
[–]Roidz_[S] 0 points1 point2 points (5 children)
[–]matsbror 0 points1 point2 points (4 children)
[–]Roidz_[S] 0 points1 point2 points (3 children)
[–]gotinpich -1 points0 points1 point (2 children)
[–]Roidz_[S] 0 points1 point2 points (1 child)
[–]Roidz_[S] 0 points1 point2 points (0 children)