If statement for additional column

Hello
I have a problem with the following code
It is supposed to create something like a chessboard using symbols for n symbols as side of a square and n squares for side of a chessboard
My question is how to make an if statement for odd cases of n. Because I added that it will create additional row at the top, but I'm struggling how to create such column at the end or at the beginning of the square. Basically I have no idea how to create if statement that will make one column that will look like
1*n
n
0*n
n
1*n
n
0*n
n
1*n
n
I feel like this is hard to explain for me what is the problem but hopefully it is understandable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include "pch.h"
#include <iostream>
using namespace std;
int main()
{
	int size;
	cout << " Input the number of characters for a side: ";
	cin >> size;
	int size2 = size;
	cout << endl;
	int row2 = 1;
	if (size2 % 2 == 1) {
		for (int row = 1; row <= size; ++row)
		{
			for (int col = 1; col <= size / 2; ++col)
			{
				for (int row = 1; row <= size; ++row)
					cout << "1 ";
				for (int row = 1; row <= size; ++row)
					cout << "0 ";
			}
			cout << endl;
		}
	}
	for (row2; row2 <= size/2; ++row2)
	{
		
			for (int row = 1; row <= size; ++row)
			{
				for (int col = 1; col <= size/2; ++col)
				{
					for (int row = 1; row <= size; ++row)
					cout << "0 ";
					for (int row = 1; row <= size; ++row)
					cout << "1 ";
				}
				cout << endl;
			}

			for (int row = 1; row <= size; ++row)
			{
				for (int col = 1; col <= size/2; ++col)
				{
					for (int row = 1; row <= size; ++row)
					cout << "1 ";
					for (int row = 1; row <= size; ++row)
					cout << "0 ";
				}
				cout << endl;
			}
		
	}
		return 0;
	}
I'm not quite sure what you do ask.

Is it just the math?
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main()
{
	for ( int row=0; row < 10; ++row ) {
	    std::cout << row << '\t';

	    if ( !(row % 2) ) std::cout << ( row % 4 ? "0*" : "1*" );
	    std::cout << "n\n";
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
int size;
cout << " Input the number of characters for a side: ";
cin >> size;
bool b = true;
for(int l = 0; l < size; l++) {
  for(int k = 0; k < size; k++) {
	   if(l % 2 == 0) {
	       b = true;
	   }
	   else {
	       b = false;
	   }
	for(int j = 0; j < size; j++) {
          for(int i=0; i < size; i++) {
            cout << b;   
          }//i
          b = !b;
       }//j
      cout << endl;
  }//k
}//l

		return 0;
	}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int main()
{
   const char SYM[2] = { '1', '0' };
   int N;
   cout << "Input N: ";   cin >> N;   cout << '\n';

   for ( int I = 0; I < N; I++ )
   {
      for ( int i = 0; i < N; i++ )
      {
         for ( int J = 0; J < N; J++ )
         {
            char c = SYM[ ( I + J ) % 2];
            for ( int j = 0; j < N; j++ ) cout << c;
         }
         cout << '\n';
      }
   }
}


Input N: 4

1111000011110000
1111000011110000
1111000011110000
1111000011110000
0000111100001111
0000111100001111
0000111100001111
0000111100001111
1111000011110000
1111000011110000
1111000011110000
1111000011110000
0000111100001111
0000111100001111
0000111100001111
0000111100001111


Input N: 5

1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
0000011111000001111100000
0000011111000001111100000
0000011111000001111100000
0000011111000001111100000
0000011111000001111100000
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
0000011111000001111100000
0000011111000001111100000
0000011111000001111100000
0000011111000001111100000
0000011111000001111100000
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
1111100000111110000011111
Topic archived. No new replies allowed.