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