我编写了一个简单的地图绘图程序,但有一些我无法识别的错误。简单的地图绘制问题
- 该错误只发生在X坐标为正数时,其正数为负数时出现。
- 当我的范围仅为11时,为什么会打印最后一列点?
下面的代码:
int xRange = 11;
int yRange = 11;
string _space = " ";
string _star = " * ";
for(int x = xRange; x > 0; x--)
{
for(int y = 0; y < yRange; y++)
{
int currentX = x - 6;
int currentY = y - 5;
//demo input
int testX = 2; //<----------ERROR for +ve int, correct for -ve
int testY = -4; //<-------- Y is working ok for +ve and -ve int
//Print x-axis
if(currentY == 0)
{
if(currentX < 0)
cout << currentX << " ";
else
cout << " " << currentX << " ";
}
//Print y-axis
if(currentX == 0)
{
if(currentY < 0)
cout << currentY << " ";
else
//0 printed in x axis already
if(currentY != 0)
cout << " " << currentY << " ";
}
else if(currentY == testX and currentX == testY)
cout << _star;
else
cout << " . ";
}
//print new line every completed row print
cout << endl;
}
的输出中为演示输入(X:2,Y:-4):(在从图3示出了X这是错误的)
. . . . . 5 . . . . . .
. . . . . 4 . . . . . .
. . . . . 3 . . . . . .
. . . . . 2 . . . . . .
. . . . . 1 . . . . . .
-5 -4 -3 -2 -1 0 1 2 3 4 5
. . . . . -1 . . . . . .
. . . . . -2 . . . . . .
. . . . . -3 . . . . . .
. . . . . -4 . . * . . .
. . . . . -5 . . . . . .
为演示输入输出(:-2,Y:×4):
. . . . . 5 . . . . . .
. . . * . 4 . . . . . .
. . . . . 3 . . . . . .
. . . . . 2 . . . . . .
. . . . . 1 . . . . . .
-5 -4 -3 -2 -1 0 1 2 3 4 5
. . . . . -1 . . . . . .
. . . . . -2 . . . . . .
. . . . . -3 . . . . . .
. . . . . -4 . . . . . .
. . . . . -5 . . . . . .
谁能帮助识别这两个proble米在我的代码?谢谢。
你比较'currentY == testX和currentX == testY',这是一个混合还是打算? – Kninnug