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.
#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.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <fstream>
#include <math.h>
usingnamespace 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
elseif( 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
elseif (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();
}