8x8 Checkerboard

Hey guys so I just started my 2nd computer science class. My issue is that my first computer science professor was a god awful teacher and spent 95% of the semester teaching us pseudocode, flowcharts, machine language, binary, and his own special version of shell code. He spent so much time on that stuff that he neglected to actually teach us how to code in c++. Well fast forward to my current class where my teacher is asking us to design a checkerboard for our first assignment, fully expecting us to understand c++ and I dont even know where to begin except for #include <iostream> and using namespace std, int main(), { return 0;}. Thats about all i know when it comes to c++. I have tons of pages of definitions that briefly explain different stuff like variables and constants. But I dont know how to bring it all together into code.

Here is some code that I found on the internet that shows basically what I need but I need 8 rows and 8 columns. Could you guys help me out and show me what to do to transform this code into something simple and easy that gets me what I want. Sorry for the novel and I apologize that I dont know much but this assignment is due tomorrow at 1pm rather than at 11:59 pm like every other professor ive ever had. And Ill be at work tomorrow at that time and wont have time to finish tomorrow. Im tearing my hair out over this please help. It should look like this. (I dont know why when I post this the checkboard I have typed here is just perfectly lined up rows but the first row needs to be indented and so on)


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







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>
#include <string>
using namespace std;

int main()
{

  const size_t N = 8;
	const char c1 = '*', c2 = ' ';

	for ( size_t i = 0; i < N; i++ )
	{
		for ( size_t j = 0; j < N; j++ )
		{
			std::cout << ( ( i + j ) % 2 == 0 ? c1 : c2 );
		}
		std::cout << std::endl;
	}

	return 0;


}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
# include <iostream>

int main() {
  static constexpr int side_length = 8; // number of rows and columns
  
  for (int col = 0; col < side_length; ++col) {
    for (int row = 0; row < side_length; ++row) 
      std::cout << ((col % 2 == row % 2)? ' ': '*');
    std::cout << '\n';
  } 
}


Edit: to preserve formatting in this forum, surround your output with [output] tags. For example,
[output] * * * *
* * * * [/output]
Produces
  *  *  *  *
*  *  *  *  
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;

string operator *( int n, string s )
{
   string result;
   while ( n-- ) result += s;
   return result;
}

int main()
{
   cout << 4 * ( 4 * string( " *" ) + '\n' + 4 * string( "* " ) + '\n' );
}


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

Your checker board is actually a 2D array. Maybe read this first:
https://www.tutorialspoint.com/cplusplus/cpp_multi_dimensional_arrays.htm

@lastchance
why do you want to show operator overloading to a total newbie ??????????
Topic archived. No new replies allowed.