Box on the output screen

I just wanted a box on the output screen and I wrote the program as follows. I got an error stating "UNDEFINED SYMBOL j"

Any help will be highly appreciated

The program is as follows
#include <iostream.h>
#include <conio.h>
void box(int a,int b,int c,int d)
{
for(int i=a;i<c;i++)
{
gotoxy(i,b); cprintf("\xcd");
gotoxy(i,d); cprintf("\xcd");
}
for(int j=b;j<d;j++)

gotoxy(a,j); cprintf("\xba");
gotoxy(c,j); cprintf("\xba");

gotoxy(a,b); cprintf("\xca");
gotoxy(c,b); cprintf("\xbb");
gotoxy(a,d); cprintf("\xc8");
gotoxy(c,d); cprintf("\xbc");
}
void main()
{
box(5,6,20,20);
getch();
}
you don't have braces after the second for loop. only the first statement after the loop is being considered as part of the loop.
Last edited on
Thx a lot for ur reply!

Did u mean after the second for loop?
yes
I did as directed.

This is the new one:

#include <iostream.h>
#include <conio.h>
void box(int a,int b,int c,int d)
{
for(int i=a;i<c;i++)
{
gotoxy(i,b); cprintf("\xcd");
gotoxy(i,d); cprintf("\xcd");
}
for(int j=b;j<d;j++)
{
gotoxy(a,j); cprintf("\xba");
gotoxy(c,j); cprintf("\xba");

gotoxy(a,b); cprintf("\xca");
gotoxy(c,b); cprintf("\xbb");
gotoxy(a,d); cprintf("\xc8");
gotoxy(c,d); cprintf("\xbc");
}
void main()
{
box(5,6,20,20);
getch();
}
}

Still am getting two more errors
(i) Declaration syntax error
(ii) Declaration syntax missing ;

Your help will be greatly appreciated
Also,A big thx for ur continued support!
That's because there are still errors in the braces.
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
#include <iostream.h>
#include <conio.h>
void box(int a,int b,int c,int d)
{
for(int i=a;i<c;i++)
{
gotoxy(i,b); cprintf("\xcd");
gotoxy(i,d); cprintf("\xcd");
}
for(int j=b;j<d;j++)
{
gotoxy(a,j); cprintf("\xba");
gotoxy(c,j); cprintf("\xba");

gotoxy(a,b); cprintf("\xca");
gotoxy(c,b); cprintf("\xbb");
gotoxy(a,d); cprintf("\xc8");
gotoxy(c,d); cprintf("\xbc");
}
} // added this closing brace to end the function.
void main()
{
box(5,6,20,20);
getch();
}
// removed the last unnecassary closing brace. 


EDIT: It will help if you indent your code.
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
#include <iostream.h>
#include <conio.h>

void box(int a,int b,int c,int d)
{
  for(int i=a;i<c;i++)
  {
    gotoxy(i,b); cprintf("\xcd");
    gotoxy(i,d); cprintf("\xcd");
  }
  for(int j=b;j<d;j++)
  {
    gotoxy(a,j); cprintf("\xba");
    gotoxy(c,j); cprintf("\xba");

    gotoxy(a,b); cprintf("\xca");
    gotoxy(c,b); cprintf("\xbb");
    gotoxy(a,d); cprintf("\xc8");
    gotoxy(c,d); cprintf("\xbc");
  }
} // added this closing brace to end the function.

void main()
{
  box(5,6,20,20);
  getch();
}
// removed the last unnecassary closing brace. 
Last edited on
Its working well!

A million thx!

May God bless you in abundance.
Topic archived. No new replies allowed.