just define a
string border(20,'#')
and
cout it before and after the sides:
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
string border( 20, '#');
string spaces( 20, ' ' );
cout<< '#' << border << "#\n";
cout<< '#' << spaces << "#\n";
cout<< '#' << spaces << "#\n";
cout<< '#' << spaces << "#\n";
cout<< '#' << spaces << "#\n";
cout<< '#' << border << "#\n";
system("pause");
return 0;
}
But now try to understand this:
#include <string>
#include <iostream>
int main()
{
static const int WIDTH=18;
static const int HEIGHT=8;
std::string border(WIDTH-2,'#');
std::string spaces(WIDTH-2,' ');
std::cout << '#' << border << '#' << std::endl;
for(unsigned int i=1; i<HEIGHT-1; ++i)
{
std::cout << '#' << spaces << '#' << std::endl;
}
std::cout << '#' << border << '#' << std::endl;
system("pause");
return 0;
}
Do you understand the use of constants and of the control structures ?!?