# Thread: drawing boxes

1. ## drawing boxes

Hello

I need some help with drawing boxes. I can draw triangles, but boxes i am having trouble with.

I need to draw a box like this ...

####
# #
####

It needs to be hollow, not like a triangle ...

*
**
***

Does anybody know an algorithm to draw a box?

eg height = 3
width = 5

output

#####
# #
#####

Anybody have any hints?

thanku

2. > Anybody have any hints?

Yeah. The easiest is to use the search button and find all the other people doing homework that have asked the same thing...

draw the top row (x number of stars)
for x-2 times, draw: 1 star, x-2 spaces, 1 star
draw the bottom row (x number of stars)

Very simple stuff

Quzah.

3. Declare two boundary variables, rows and cols. When cols has the value 0 or the maximum number of columns then you print the filler character, in this case '#'. When rows has the value 0 or the maximum number of rows, fill the entire row. Simple.
Code:
The numbers are column numbers:
Row 1: 01234567
Row 2: 0      7
Row 3: 0      7
Row 4: 0      7
Row 5: 01234567
Enjoy

-Prelude

4. heres a function I wrote ages ago to draw a box of whatever size, and before ANYONE says its not compatible because of cprintf, they can save there breath, I needed colour, i needed it to work on a ibm and this is the easiest, quickest and simplest way, also used ibm ascii characters for the border but change them as you wish and change it to a printf if you like:

Code:
void border(int x1,int y1,int x2,int y2)
{
int temppos;

gotoxy(x1,y1);
cprintf("É");
for (temppos=x1;x2-temppos>1;temppos++)
cprintf("Í");
cprintf("»");
for (temppos=y1+1;y2-temppos>0;temppos++)
{
gotoxy(x1,temppos);
cprintf("º");
gotoxy(x2,temppos);
cprintf("º");
}
gotoxy(x1,y2);
cprintf("È");
for (temppos=x1;x2-temppos>1;temppos++)
cprintf("Í");
cprintf("¼");
gotoxy(x1,y1);
}
acsii chars dont show up in windows though.

5. >and before ANYONE says its not compatible
I considered my usual portability rant, but I decided that you obviously know better. So I won't bother anymore as long as you let everyone know that it may not work on all systems. Now, if you use undefined behavior, expect me to start ranting.

-Prelude

6. haha, fair enough

Popular pages Recent additions