I’m drawing a cross in the console. Here’s my code:
for (int x = 0; x < 320; x++)
{
for (int y = 0; y < 100; y++)
{
Console.SetCursorPosition(Convert.ToInt32(x / 4),Convert.ToInt32(y / 4));
if (x == 160)
{
if (y == 50)
{
Console.Write("┼");
}
else
{
Console.Write("│");
}
}
else
{
if (y == 50)
{
Console.Write("─");
}
}
}
}
The console draws the cross except the middle “┼” symbol. When I debugged the program it hit the Console.Write("┼"); line. Instead the program written the “─” symbol. What I’m doing wrong and how to solve this problem?
The problem seems to be that you are writing to each location multiple times because of the part where you divide by 4.
When (x, y) is (160, 50) you write a cross at (40, 12). Then (x, y) is (160, 51) so you write a vertical pipe at the same location, overwriting the cross. Then later when (x, y) becomes (161, 50) you overwrite the pipe with a dash.
Try this instead: