Skip to content

Instantly share code, notes, and snippets.

@WilliamGarrow
Last active February 10, 2022 11:29
Show Gist options
  • Save WilliamGarrow/58052941fc5741f89649 to your computer and use it in GitHub Desktop.
Save WilliamGarrow/58052941fc5741f89649 to your computer and use it in GitHub Desktop.
DEV204x Programming with C# - Module Two Assignment
/// Module Two Assignment
using System;
namespace ModuleTwoAssignment
{
class Program
{
static void Main(string[] args)
{
for (int column = 0; column < 8; column++) // will create 8 row x 8 column pattern
{
for (int row = 0; row < 8; row++)
{
if ((row + column) % 2 == 0)
{
Console.Write("X");
}
else if ((row + column) % 2 == 1)
{
Console.Write("O");
}
else
{
Console.Write("Neither X nor O"); // Built in unit test if logic for X and O fails
}
}
Console.WriteLine();
}
}
}
}
/*
Output:
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
XOXOXOXO
OXOXOXOX
*/
/// Module Two Assignment
/// For this assignment, you will create the pattern of a chess board that is 8 x 8.
/// Use X and O to represent the squares.
/// 1. Create the appropriate nested looping structure to output the characters in an
/// 8 x 8 grid on the screen using Console.Write() or Console.WriteLine() as appropriate.
/// 2. Include a decision structure to ensure that alternate rows start with opposite
/// characters as a real chess board alternates the colors among rows.
/// This is what your output should look like.
/// XOXOXOXO
/// OXOXOXOX
/// XOXOXOXO
/// OXOXOXOX
/// XOXOXOXO
/// OXOXOXOX
/// XOXOXOXO
/// OXOXOXOX
/// Grading Criteria:
/// Used a nested loop
/// Used a decision structure to flip row output
/// Output is correct per above image
@tunacinsoy
Copy link

Thanks! I was struggling with the pattern, I've created a pyramid with those X and O's :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment