Проблемы: Некоторые проблемы, которые я вижу в своем коде, связаны с устойчивостью к ошибкам, например, получение клетчатой доски с тремя ширинами и четырьмя высотами. Когда я пишу один для высоты и один для ширины, высота не отображается. Есть и другие причины для проверки ошибок, позволяющие предотвратить сбой моего приложения.
Я создал шахматную доску. В следующем цикле for:
Глобальные переменные (W) для ширины и (H) для высоты.
Код: Выделить всё
// H is for Height
int H = 2;
// W is for Width
int W = 2;
/*For loop with indexer (i);
* We want the height of the checkboard to be less than the (height divided by two) or by half;
* The completion of a loop, we iterate the index by one
*/
for (var i = 0; i < (H/2); i++)
{
/*For loop with indexer (j);
* We want the width of the checkboard to be less than the (width divided by two) or by half;
* The completion of a loop, we iterate the index by one
*/
for (var j = 0; j < (W/2); j++)
{
// Printing the text of an asterisk followed by a space.
Console.Write("* ");
}
//Console WriteLine jumps the pointer to another line.
Console.WriteLine();
/*For loop with indexer (j);
* We want the width of the checkboard to be less than the (width divided by two) or by half;
* The completion of a loop, we iterate the index by one
*/
for (var j = 0; j < (W/2); j++)
{
// Printing the text of a space followed by an asterisk.
Console.Write(" *");
}
//Console WriteLine jumps the pointer to another line.
Console.WriteLine();
}
//Reference of Inspiration Link: https://stackoverflow.com/questions/78974544/c-sharp-creating-a-square
Я добавил тире и штриховые линии, чтобы визуализировать места, в которых находится мой код. написано.
Я ожидаю следующего вывода, который и получаю.
Код: Выделить всё
--
|* |
| *|
--
Подробнее здесь: https://stackoverflow.com/questions/789 ... -asterisks