I am making a board game and I want to test the layout in the
terminal before I draw anything. Ask me how big the board is
and print it with the squares alternating, like a chessboard.
Top-left square should be a filled one.
Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.
Notes
Every square has to ask a question before it prints. Activity 1.21 printed the same character every time; this one does not.
The answer depends on both loop counters, not one of them. A condition that only looks at the row gives you stripes. Build a four-by-four version on paper first and stare at which squares are filled.
The tool you need is the remainder operator from Activity 1.6 — the one that tells you whether a number is even. There is more than one correct condition and they are worth comparing.
Start it on the wrong color and everything still works, because an inverted checkerboard is still a checkerboard. The brief says which square is filled, so check the top-left corner against it.
Test with 8, then 1, then 0. All three should do something sensible and none of them should crash.
Sample Output
Sample Output
Size? 8 [Enter]
# . # . # . # .
. # . # . # . #
# . # . # . # .
. # . # . # . #
# . # . # . # .
. # . # . # . #
# . # . # . # .
. # . # . # . #
The tell is the second row, not the first. Anyone can get one row alternating; the board is only right when row 2 starts with the opposite square to row 1.
Submit
Your requirements list and your program file, named cc-checkerboard.