# Creating a box using C++



## jacy (Jul 19, 2004)

Hi,
I am trying to create a box using C++. I am only able to create half of the box. Here is my code.

#include<iostream.h>
int main ()
{
int i;
for(i=0;i<10;i++)
cout<<'*'<<"\n"; //prints a vertical line
for(i=0;i<10;i++)
cout<<'*'<<" "; //prinsts a horizontal line
return 0;
}
Here is how the output looks like.
*
*
*
*
*
*
*
*
* * * * * * * * *

Now i dont know how to print a vertical line upwards and the other horizontal line , in order to make a complete box. Can anyone please suggest me something, thanks.


----------



## aewarnick (Sep 3, 2002)

Do one row at a time in the loop and do the first and last rows separate from the loop.

**** //first
* * //loop
* * //loop
**** //last

Coding this is extremely simple. You have the idea. You just need to tweak your thinking; do one ROW at a time.


----------



## jacy (Jul 19, 2004)

Thanks aewarnick, This is how my program looks like now.

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int i;
for (i=0; i<5; i++)
cout<<'*'<<" "; //prints the first row
i=1;
while (i<5)
{ 
cout<<"\n"<<'*'<<setw(12)<<'*'; //prints the second row and so on
i++; 
}
cout<<"\n";
for (i=0;i<5; i++)
cout<<'*'<<" "; // prints the last row
cin.get();
return 0;
}

Thanks a lot am getting the desired output.


----------



## jacy (Jul 19, 2004)

Hi can u also provide me with some intermediate C++ coding exercises, thanks


----------



## aewarnick (Sep 3, 2002)

The best thing to do is to think of something you want to do, start coding it and ask questions when you need help.


----------

