![]() |
| | #1 |
| Registered User Join Date: Sep 2005 Location: California
Posts: 53
| Hollow square Code: #include <iostream>
using namespace std;
// begins program execution
int main()
{
int side; // holds size of side of square
int i,j; // holds counters; i = row and j = column
cout << "Input the size of a side of a square (1-20): "; // asks user for size of the side
cin >> side;
// for top row
for ( i = 0; i < side; ++i)
{
cout << "*";
}
// for middle rows subtract 2 to adjust for first and last row
for ( i = 0; i < ( side - 2 ); ++i)
{
cout << "*";
// subtract 2 to adjust for first and last columns
for ( j = 0; j < ( side - 2 ); ++j)
{
cout << " ";
}
cout << "*" << endl;
}
// for bottom row
for ( i = 0; i < side; ++i)
{
cout << "*";
}
cout << endl;
return 0;
} // end main function
__________________ THE redheaded stepchild. |
| Kayoss is offline | |
| | #2 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| What's the output? It looks good as far as I can see.
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort |
| dwks is offline | |
| | #3 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| Oh yes, I ran it, and: Code: // for top row
for ( i = 0; i < side; ++i)
{
cout << "*";
}
cout << endl; // need a newline
// for middle rows subtract 2 to adjust for first and last row
for ( i = 0; i < ( side - 2 ); ++i)
{
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort |
| dwks is offline | |
| | #4 |
| Registered User Join Date: Mar 2002
Posts: 1,595
| It looks like you need to enter a new line or an endl after the first line of asterixes and before you start the second line.
__________________ You're only born perfect. |
| elad is offline | |
| | #5 |
| Registered User Join Date: Sep 2005 Location: California
Posts: 53
| Too easy! Thanks much.
__________________ THE redheaded stepchild. |
| Kayoss is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| hollow square | mdnealy | C# Programming | 8 | 07-05-2009 03:23 PM |
| Loop seg error | Zishaan | Game Programming | 2 | 03-28-2007 01:27 PM |
| Forced moves trouble!! | Zishaan | Game Programming | 0 | 03-27-2007 06:57 PM |
| Help with my draughts game | Zishaan | C++ Programming | 9 | 03-24-2007 07:33 AM |
| hollow square | jms318 | C Programming | 5 | 11-30-2006 11:36 PM |