|
-
October 7th, 2005, 04:35 PM
#1
Nested Loops help
Ok, sorry for the post, tried searching around online, this seems to be a general program students have to do when the nested loops chapter comes around, couldnt find much information.
Basically I need to write a program that asks the user to enter a number, then the output is a diamond made up a number of rows the user put. Making a nested loops to output this is easy:
*
**
***
****
*****
however I can't figure out how to get the opposite side of the triangle, ie:
(replace - with a blank space, wouldnt show up right if I just did spaces)
----*
---**
--***
-****
*****
This is the only part that has me stumpted, once I get the nested loop right to have the spaces first, then print the asteriks I shouldnt have any problem getting the bottom half to print up. Any help would be greatly apprechiated. The code I am using for the first triangle example is:
for ( int row = 1; row <= 5; ++row){
for ( int col = 1; col <= row; ++col )
cout << "*";
cout << "\n";
}
I'm sure it's something very simple and I'm just making things worse and worse.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|