Drawing a rectangle
Jan 27, 2009 at 5:37pm UTC
I can't figure out how to draw a rectangle. I know it has two loops, one for counting cols and the other for counting rows. I just can't code it correctly.
1 2 3 4 5 6 7 8 9 10 11 12 13
for (int i=1; i<24; i++)
{
for (int k=1; k<82; k++)
{
if (k==79)
{
cout << "*" ;
k=1;
}
cout << " " ;
}
cout << "*" ;
}
Jan 27, 2009 at 6:02pm UTC
If you want a filled rectangle you can do:
1 2 3 4 5 6 7 8
for (int r=0;r!=5;++r)
{
for (int c=0;c!=10;++c)
{
cout<<"*" ;
}
cout<<"*" <<endl;
}
Last edited on Jan 27, 2009 at 6:03pm UTC
Jan 27, 2009 at 6:03pm UTC
No, i dont want it filled.
Jan 27, 2009 at 6:13pm UTC
Ok, found out.
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
#include <iostream.h>
#include <string.h>
void main()
{
for (int z=1; z<=79; z++)
{
cout << "*" ;
}
cout << endl;
for (int i=1; i<=5; i++)
{
cout << "*" ;
for (int j=1; j<=77; j++)
{
cout << " " ;
}
cout << "*" << endl;
}
for (int y=1; y<=79; y++)
{
cout << "*" ;
}
cout << endl;
}
Topic archived. No new replies allowed.