Need Help to Create a Chess program in C++

A

asif929

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 appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****




#include <iostream>

using namespace std;

int main()
{
for (int row = 1; row < 9; row++)// Draw big row 8 times
{
for (int row1 = 1; row1 < 4; row1++) //Draw a little row 3 times
{
for (int col = 1; col < 9; col++) //Draw a big column 8 times
{
for (int col1 = 1; col1 < 6; col1++) //Draw a character 5
times
{
if (col % 2 == 0 && row % 2 == 0)
{
cout <<' ';
}
else
{
cout << '*';
}
if(col1%2 == 0 && row1 % 2 ==0)
{
cout <<' ';
}
else
{
cout << '*';
}
}

}
}
}

return 0;
} // function main
 
M

Mark P

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 appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
I didn't actually run your code but just from glancing at it there's a
glaring problem. You never output any line breaks! Try to find the
appropriate place to insert those.
 
J

Jim Langston

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 appreciate if somebody help me out of this to debug the program
below. The chess board suppose to be printed with "*" and space " " as
you can see below as an example. Again I would appreciate for your help
in advance.

sample print or output:

***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****
***** ***** ***** *****




#include <iostream>

using namespace std;

int main()
{
for (int row = 1; row < 9; row++)// Draw big row 8 times
{
for (int row1 = 1; row1 < 4; row1++) //Draw a little row 3 times
{
for (int col = 1; col < 9; col++) //Draw a big column 8 times
{
for (int col1 = 1; col1 < 6; col1++) //Draw a character 5
times
{
if (col % 2 == 0 && row % 2 == 0)
{
cout <<' ';
}
else
{
cout << '*';
}
if(col1%2 == 0 && row1 % 2 ==0)
{
cout <<' ';
}
else
{
cout << '*';
}
}

}
}
}

return 0;
} // function main

Consider breaking it down into simpler steps.

#include <iostream>
#include <string>

void OutputChar( char ThisChar, size_t times )
{
for ( size_t i = 0; i < times; ++i )
std::cout << ThisChar;
}

void OutputLine1()
{
for ( int i = 0; i < 4; ++i )
{
OutputChar( '*', 5 );
OutputChar( ' ', 5 );
}
std::cout << "\n";
}

void OutputLine2()
{
for ( int i = 0; i < 4; ++i )
{
OutputChar( ' ', 5 );
OutputChar( '*', 5 );
}
std::cout << "\n";
}

void OutputBoard()
{
for ( int i = 0; i < 4; ++i )
{
for ( int j = 0; j < 5; ++j )
OutputLine1();
for ( int j = 0; j < 5; ++j )
OutputLine2();
}
}

int main()
{

OutputBoard();

std::string wait;
std::getline( std::cin, wait );
return 0;
}
 
N

n.torrey.pines

Jim said:
Consider breaking it down into simpler steps.

#include <iostream>
#include <string>

void OutputChar( char ThisChar, size_t times )
{
for ( size_t i = 0; i < times; ++i )
std::cout << ThisChar;
}

void OutputLine1()
{
for ( int i = 0; i < 4; ++i )
{
OutputChar( '*', 5 );
OutputChar( ' ', 5 );
}
std::cout << "\n";
}

void OutputLine2()
{
for ( int i = 0; i < 4; ++i )
{
OutputChar( ' ', 5 );
OutputChar( '*', 5 );
}
std::cout << "\n";
}

void OutputBoard()
{
for ( int i = 0; i < 4; ++i )
{
for ( int j = 0; j < 5; ++j )
OutputLine1();
for ( int j = 0; j < 5; ++j )
OutputLine2();
}
}

int main()
{

OutputBoard();

std::string wait;
std::getline( std::cin, wait );
return 0;
}

Or simply

#include <iostream>

int main() {
for(int i = 0; i < 3*8; ++i) {
for(int j = 0; j < 5*8; ++j)
std::cout << ((i/3)%2 == (j/5)%2 ? '*' : ' ');
std::cout << '\n';
}
}
 
A

asif929

Thanks guys for the help. i am glad to tell you that i figure out the
progam myself. I worte it below.I tried your program its not compiling
and for more info i am using putty for connecting and compiling.



#include <iostream>

using namespace std;
int main()
{

cout << endl;

for ( int mm = 1; mm < 5; mm++ )
{
for ( int row = 0; row < 3; row++ )
{
for ( int column = 0; column < 4; column++ )
{

for ( int i = 1; i < 6; i++ )

cout << "*";

for ( int j = 1; j < 6; j++)

cout << " ";

} // for column

cout << endl;

} // for row

for ( int row2 = 0; row2 < 3; row2++ )
{

for ( int column2 = 0; column2 < 4; column2++ )
{

for (int i2 = 1; i2 < 6; i2++)

cout << " ";

for ( int j2 = 1; j2 < 6; j2++ )

cout<< "*";

} // for column2

cout << endl;

} // for row2

} // for mm

return 0;
} // function main
 
A

asif929

I have another program to write, i will appreciate if somebody can
help......prompts the user to enter positive integer, and then prints
out four triangles
For Example: If we enter 4 it shouls shows

*
* *
* * *
* * * *

* * * *
* * *
* *
*


* * * *
* * *
* *
*

*
* *
* * *
* * * *

Thanks again.
 
A

Alf P. Steinbach

* (e-mail address removed):
I have another program to write, i will appreciate if somebody can
help......prompts the user to enter positive integer, and then prints
out four triangles
For Example: If we enter 4 it shouls shows

*
* *
* * *
* * * *

* * * *
* * *
* *
*


* * * *
* * *
* *
*

*
* *
* * *
* * * *

See the FAQ for reasons why you should (1) stop TOP-POSTING, and (2)
stop asking for solutions to HOMEWORK.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,745
Messages
2,569,485
Members
44,909
Latest member
DestinyKetoScam

Latest Threads

Top