Where did my lines go?

Hello. I am currently searching for two missing lines. The code is this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <vector>
#include "conio.h"
#include "windows.h"



using namespace std;

typedef struct _Rect{
int left;
int top;
int right;
int bottom;

}Rect;

void gotoxy(int x, int y)
 {
   static HANDLE hStdout = NULL;
   COORD coord;

   coord.X = x;
   coord.Y = y;

   if(!hStdout)
   {
     hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
   }

   SetConsoleCursorPosition(hStdout,coord);
 }


void DrawRect(Rect rect){

int x1=rect.left, x2=rect.right, y1=rect.top, y2=rect.bottom;
int i;

//horisontella sidor
gotoxy(x1+1, y1); for(i=0; i<x2-x1; i++); cout<<(char)255;
gotoxy(x1+1, y2); for(i=0; i<x2-x1; i++); cout<<(char)255;

//vertikala sidor

for(i=0; i<y2-y1; i++){gotoxy(x1, y1+i); cout<<(char)179;}
for(i=0; i<y2-y1; i++){gotoxy(x2, y1+i); cout<<(char)179;}


gotoxy(x1, y1); cout<< (char)218; //övre vänster hörn
gotoxy(x2, y1); cout<< (char)191; //övre högra hörn
gotoxy(x1, y2); cout<< (char)192; //nedre vänsta hörn
gotoxy(x2, y2); cout<< (char)217; //nedre högra hörn


}

int main()
{
    Rect aRect={30, 3, 49, 14};
    //int width=aRect.right-aRect.left, heigth=aRect.bottom-aRect.top;

    DrawRect(aRect);

    return 0;
}


However only the vertical lines draws, what am I doing wrong?

Thanks in advance!
@shooninjo

Well, for one, char(255) is nothing that's printable. You needed char(196). Plus, the for loop is never incremented, a 1 was added, but that's all. It should have been increased by i, like the verticals. And lastly, for the horizontal line loops, you had a semi-colon after the for statement, which shouldn't be there. Here is your program, with corrections.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <vector>
#include "conio.h"
#include "windows.h"



using namespace std;

typedef struct _Rect{
	int left;
	int top;
	int right;
	int bottom;

}Rect;

void gotoxy(int x, int y)
{
	static HANDLE hStdout = NULL;
	COORD coord;

	coord.X = x;
	coord.Y = y;

	if(!hStdout)
	{
		hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
	}

	SetConsoleCursorPosition(hStdout,coord);
}


void DrawRect(Rect rect)
{

	int x1=rect.left, x2=rect.right, y1=rect.top, y2=rect.bottom;
	int i;

	//horisontella sidor
	
	for(i=0; i<x2-x1; i++)
	{
		gotoxy(x1+i, y1);
		cout<<(char)196;
	}
	
	for(i=0; i<x2-x1; i++)
	{
		gotoxy(x1+i, y2);
		cout<<(char)196;
	}

	//vertikala sidor

	for(i=0; i<y2-y1; i++)
	{
		gotoxy(x1, y1+i);
		cout<<(char)179;
	}
	for(i=0; i<y2-y1; i++)
	{
		gotoxy(x2, y1+i);
		cout<<(char)179;
	}


	gotoxy(x1, y1);
	cout<< (char)218; //övre vänster hörn
	gotoxy(x2, y1);
	cout<< (char)191; //övre högra hörn
	gotoxy(x1, y2); 
	cout<< (char)192; //nedre vänsta hörn
	gotoxy(x2, y2);
	cout<< (char)217; //nedre högra hörn
}

int main()
{
	Rect aRect={30, 3, 49, 14};
	//int width=aRect.right-aRect.left, heigth=aRect.bottom-aRect.top;

	DrawRect(aRect);
	cout << endl << endl;

	return 0;
}
Last edited on
Thanks :)
Topic archived. No new replies allowed.