Thread: Help me to draw a hollow rectangle in C++!

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    3

    Question Help me to draw a hollow rectangle in C++!

    Hi guys,
    Again, I'm getting crazy with this. The problem is:I need to write a C++ program that draws a hollow rectangle, in which the width and the length will be inputted by users. I've tried, but with no luck. It always shows me a rectangle with the wrong length and width. Do you have any ideas about my code? Please help me with this. Thank you!!!

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    void main(void)
    {
    	int d, r, i, m, n;
    	printf("Enter length:");
    	scanf("%d", &d);
    	printf("Enter width:");
    	scanf("%d", &r);
    	for(i=1; i <= r; i++)
    	{
    		for(m=0; m<=r; m++)
    		{
    		printf(" ");
    		}
    		for(n=0; n<=d-m; n++)
    		{
    		if(n==0||n==d-m)
    			printf("*");
    		else if(i==r)
    			printf("*");
    		else
    			printf(" ");
    		}
    	printf("\n");
    	}
    	getch();
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    what you wrote is no C++
    Devoted my life to programming...

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This is C. Are you sure you don't mean C? Deciding which language you're going to use is a start.
    Also, void main is not standard. Use int main.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 06-23-2010, 02:58 AM
  2. Which is the better way to draw?
    By g4j31a5 in forum Game Programming
    Replies: 16
    Last Post: 01-22-2007, 11:56 PM
  3. draw function HELP!!!
    By sunoflight77 in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 11:28 PM
  4. Help With pointers in classes.
    By indigo0086 in forum C++ Programming
    Replies: 12
    Last Post: 10-10-2002, 02:03 PM
  5. hollow rectangle
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 04-07-2002, 07:03 AM