Drawing rectunglar borders using for loop and array

Have spent one hour working on this and yet can't come up with a solution. Anyone willing to help me with this. I don't even know if im using the correct approach here. if not, can you tell me what exactly I can do to draw a border. Not asking anyone to write the code for me but perhaps explain it to me how I can draw a border.

If there is a better way to do then this, then please let me know. I have use a array though.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  void doubleborder(char doublelineborder[][10],int size)

	//-----------
{
	int row=0;
	int column;
	for (row=0;row<size;row++)
	{
		
		
			for(column=0;column<10;column++)
			{
				if (row==0 || row==9)
				{
					doublelineborder[row][column]=(char)(196);
					cout<<doublelineborder[row][column];
					
				
				}
				else if (row>0 && row<9 && (column==0 || column==9))
				{
					
					doublelineborder[row][column]=(char)(179);
					cout<<doublelineborder[row][column];
				}
				
			}
			cout<<endl;
			
	
	}
Here's a pretty simple way of doing a 10x10 border.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

int main( int argc, char* argv[] )
{
    int r, c;

    for( r = 0; r < 10; ++r )
    {
        for( c = 0; c < 10; ++c )
        {
            if( r == 0 || r == 9 )
            {
                std::cout << "*";
            }
            else
            {
                if( c == 0 || c == 9 )
                    std::cout << "*";
                else
                    std::cout << " ";
            }
        }
        std::cout << "\n";
    }

    return 0;
}


I don't really see the point of the array in your code unless you print the border outside of that function some place. It doesn't seem right to have both the assignments and the prints in there.
hi,
this program draw for you a rectangular
note:you can enter the side of shape!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <fstream>
#include <math.h>

using namespace std;
void main()
{
	char sel1;
	do{
	int n;
	cout<<"\n	Rectangular\n\n	type the side of shape :  ";
	cin>>n;
	system("cls");
	cout<<"\n\n\n";
for (int i =1 ;i<=n;i++)
{
	if(i==1)
	{
		cout<<setw(8);
		for(int e = 1 ; e <= n ;e++)
		{
			cout<<'#';
		}// for e
		cout<<endl;
	 }// if
	else if( i>=2 && i<n )// 1
	{
		cout<<setw(8);
		for (int r =1 ;r<n-(n-2);r++)
		{
			cout<<'#'<<setw(n-1)<<'#'<<endl;
		}// for r
	}// else if 1
	else if (i==n)// 2
	{
		cout<<setw(8);
		for(int f = 1 ; f<= n ;f++)
		{
			cout<<'#';
		}// for f
	}// else if 2
}// for i
	cout<<"\n\n\n	shape again!? press 'c' to exit press 'e' ";
	cin>>sel1;	
	system("cls");
	}while(sel1=='c');
	cout<<"\n	GOOD LUCK ";


	_getch();
}





Thank you rahat Ihutch :) got an understanding now :)
Topic archived. No new replies allowed.