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!

oops, the last box, those middle $$ are supposed to be over more...so it looks like...a blank square inside...you get the idea :)

ok i've written some code for you. it reads the number of rows and columns and prints the drawing.

#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 :idea:

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");
}

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");
}

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 :!:

Greetings.

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

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. ;)

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
:)

This article has been dead for over six months. Start a new discussion instead.