Version: Dev-C++ 4
OS : Win98
Subject: Using “For” and “If” statement to produce a square.


Hello,

Working my way through some excises. One of the tasks is to draw a square( not rocket science I know).
I can produce the square, but I’m sure there is a more efficient means.

Some pointers please!

Code:
#include <iostream.h>

void drawSquare(int x);

int main ()
{
drawSquare(20);
return 0;
}

void drawSquare(int x )
{
for (int a =1 ; a <=x ; a++)
for (int b =1; b <=x;b++)
if (a==1 || a==x ) cout << "a" ;
else
if (a==2 && b==1) cout << "\n" << "b";
else
if(b>1 && b< x) cout << " ";
else
if (b ==1)cout <<"b";
else
cout <<"b"<<"\n";

Thanks

hmm