for loop: to draw a square a box

#include <iostream>
using namespace std;

int a;
int b;
int c;

int main()

{

for(c=0;c<=5;c++)
cout << " \t***" << endl;

for(a=0;a<=5;a++)
cout << "***" << endl;

for(b=0;b<=5;b++)
cout << "***";

}

can someone take a look at this program - I am trying to draw a square box with stars using cout command: ***
Please use code tags when you want to post something formatted.
Ex: [code] { Your code or output here } [/code]

Your program does not display a box shape for me.
It displays
 	***
 	***
 	***
 	***
 	***
 	***
***
***
***
***
***
***
****************** 


The key to these kinds of problems is recognizing the pattern when the input is a certain size.

What should your program display?
Something like this?
1
2
3
4
5
*****
*   *
*   *
*   *
*****


There's many ways to do this, but you can try expanding this program to allow it to work with different side lengths:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Example program
#include <iostream>
#include <string>

int main()
{
    std::string ends = "*****\n";
    std::string mids = "*   *\n";
    
    std::cout << ends;
    for (int i = 0; i < 3; i++)
        std::cout << mids;
    std::cout << ends;

}
Last edited on
Topic archived. No new replies allowed.