I am trying to construct an L shape which starts from a specific coordinate on screen given by the user!
(我正在尝试构造一个L形,它从用户在屏幕上给出的特定坐标开始!)
The coordinate can can be any for example: (4,5) where 4 represents the x axis while 5 represents the y axis figure.(坐标可以是任何值,例如:(4,5)其中4代表x轴,而5代表y轴图形。)
The code for L shape is given below and the code which I am trying to print on specific axis is also given.
(下面给出L形的代码,并给出我要在特定轴上打印的代码。)
Just can't get my head around how to print on a specific part because whenever I try the figure just prints out being broken.(只是无法理解如何在特定零件上进行打印,因为每当尝试尝试时,图形都会被打碎。)
int total_height , total_width, x_axis , y_axis;
cout << "Enter the height and the width ";
cin >> total_height >> total_width;
cout << endl << "Enter the axis you want to print it on: ";
cin >> x_axis >> y_axis;
int half_width = total_width / 2;
int half_height = total_height / 2;
for (int i = 0; i < total_height; i++) {
if (i < half_height) {
for (int j = 0; j < half_width; j++) {
if (i == 0) {
cout << "*";
}
else if (j == 0 || j == half_width - 1) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
else if (i == half_height) {
for (int j = 0; j < total_width; j++) {
if (j == 0) {
cout << "*";
}
else if (j < half_width - 1) {
cout << " ";
}
else {
cout << "*";
}
}
cout << endl;
}
else {
for (int j = 0; j < total_width; j++) {
if (i == total_height - 1) {
cout << "*";
}
else if (j == 0) {
cout << "*";
}
else if (j == total_width - 1) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
}
The code I am using for changing the coordinates:
(我用于更改坐标的代码:)
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
Any idea how it can be printed on the axis given by the user either by using the gotoxy function or any other function ?
(知道如何通过使用gotoxy函数或任何其他函数将其打印在用户指定的轴上吗?)
ask by CanceR227 translate from so