| | |
Printing a hollow box!
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2004
Posts: 17
Reputation:
Solved Threads: 0
hello,
im pretty new to C and for my first project, I have to print out information about a box.(exciting...) anyway, i have the user enter the width and height of the 2d box, and then give them a menu to select from, to get info about the box, perimeter, area and so on..., one of the menu options is to print out a picture of the hollow box...I'm having trouble with the logic behind this..of how to perform this action. I can print out a regular box
ie.
Selection: R
A solid Rectangle with 4 rows and 3 collumns
$$$$$$
$$$$$$
$$$$$$
$$$$$$
2 ASCII characters makes up one collumn..
but the problem im having is making it look like this...
A solid Rectangle with 4 rows and 3 collumns
$$$$$$
$$ $$
$$ $$
$$$$$$
I'm not necessarily asking for the code, but maybe the logic of behind how i could do this :cheesy:
Thanks!
im pretty new to C and for my first project, I have to print out information about a box.(exciting...) anyway, i have the user enter the width and height of the 2d box, and then give them a menu to select from, to get info about the box, perimeter, area and so on..., one of the menu options is to print out a picture of the hollow box...I'm having trouble with the logic behind this..of how to perform this action. I can print out a regular box
ie.
Selection: R
A solid Rectangle with 4 rows and 3 collumns
$$$$$$
$$$$$$
$$$$$$
$$$$$$
2 ASCII characters makes up one collumn..
but the problem im having is making it look like this...
A solid Rectangle with 4 rows and 3 collumns
$$$$$$
$$ $$
$$ $$
$$$$$$
I'm not necessarily asking for the code, but maybe the logic of behind how i could do this :cheesy:
Thanks!
ok i've written some code for you. it reads the number of rows and columns and prints the drawing.
Hope it helps!
oh something else. you know you could just use the EDIT button if you've written your message wrong
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <conio.h> void main() { clrscr(); int m,n,i,j; printf("Number of rows:");scanf("%i",&n); printf("Number of columns:");scanf("%i",&m); for (j=0;j<n;j++) printf("$$"); printf("\n"); i=0; while (i<m) { printf("$$"); for (j=1;j<n-1;j++) printf(" "); printf("$$\n"); i++; } for (j=0;j<n;j++) printf("$$"); }
Hope it helps!

oh something else. you know you could just use the EDIT button if you've written your message wrong
Greetings.
I have checked your codes. Nice work.
Found some little errors. Maybe you've mixed up rows & columns?
I have checked your codes. Nice work.
Found some little errors. Maybe you've mixed up rows & columns?
#include <stdio.h>
#include <conio.h>
void main()
{
int m,n,i,j;
printf("Number of rows:");
scanf("%i",&n);
printf("Number of columns:");
scanf("%i",&m);
for (j=0; j<m; j++)
printf("$$");
printf("\n");
i=0;
while (i<n-2)
{
printf("$$");
for (j=0; j<m-2; j++)
printf(" ");
printf("$$\n");
i++;
}
for (j=0;j<m;j++)
printf("$$");
printf("\n");
}•
•
•
•
Originally Posted by red_evolve
Greetings.
I have checked your codes. Nice work.
Found some little errors. Maybe you've mixed up rows & columns?![]()
#include <stdio.h> #include <conio.h> void main() { int m,n,i,j; printf("Number of rows:"); scanf("%i",&n); printf("Number of columns:"); scanf("%i",&m); for (j=0; j<m; j++) printf("$$"); printf("\n"); i=0; while (i<n-2) { printf("$$"); for (j=0; j<m-2; j++) printf(" "); printf("$$\n"); i++; } for (j=0;j<m;j++) printf("$$"); printf("\n"); }
You will print "number of columns" times "$$". In nufanvandal's first post, I understood that a column is made up of a "$$" and a line is made up of a "$$", "number of columns-2--minus 2 "$$-> the first and last columns". Tell me if I'm wrong :!:
Greetings.
Yeah, take a look at nuvandal's first post. Have a look at how he drew the output.
Initially, 4 rows will give:
Then, putting it altogether (4x3), 3 columns will give:
This is what I get from my understanding.
•
•
•
•
Are you sure?
You will print "number of columns" times "$$". In nufanvandal's first post, I understood that a column is made up of a "$$" and a line is made up of a "$$", "number of columns-2--minus 2 "$$-> the first and last columns". Tell me if I'm wrong
Initially, 4 rows will give:
C Syntax (Toggle Plain Text)
$ $ $ $
C Syntax (Toggle Plain Text)
$$$$$$ $$ $$ $$ $$ $$$$$$
•
•
Join Date: Jul 2004
Posts: 17
Reputation:
Solved Threads: 0
howdy,
so yeah,
One collumn is made up of two ASCII characters because printed ASCII characters are approximately twice as tall as they are wide, so to make it look more nice, and like a box, one collumn is made up of 2 characters
ie:
##
##
##
##
while one row is made up of only a single ASCII character
better example of output, each collumn is a different color
########< --1st row
########< --2nd row
########< --3rd row
so the above would be a rectangle with 4 collumns, and 3 rows
so yeah,
One collumn is made up of two ASCII characters because printed ASCII characters are approximately twice as tall as they are wide, so to make it look more nice, and like a box, one collumn is made up of 2 characters
ie:
##
##
##
##
while one row is made up of only a single ASCII character
better example of output, each collumn is a different color
########< --1st row
########< --2nd row
########< --3rd row
so the above would be a rectangle with 4 collumns, and 3 rows
![]() |
Similar Threads
- Hollow box program (C++)
- Hollow box program updated (C)
Other Threads in the C Forum
- Previous Thread: Are You Up For This Project
- Next Thread: questions &solutions
| Thread Tools | Search this Thread |
adobe ansi api array arrays bash binarysearch centimeter char character convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer license linked linkedlist linux linuxsegmentationfault list logical_drives match matrix meter microsoft motherboard multi mysql oddnumber odf open opendocumentformat openwebfoundation pattern pause pdf pointer pointers posix power problem program programming pyramidusingturboccodes read recursion recv recvblocked repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string strings structures suggestions system test testautomation unix urboc user voidmain() win32api windows.h





