For/While Loops for patterns

March 6, 2010 at 16:40:59
Specs: Windows 7
Ok here's my problem. I have been working at this for hours upon end it seems like and I just need someone to help point me in the right direction Here's what I have so far.

Ok, here's what I have right now:

#include <iostream>
int main() {
int i, k;
for (i = 0; i < 7; i++)
{
for (k = 0; k <= i; k++)
{
cout << "*";
}
cout << endl;

}
return 0;
}


This particular code runs fine. It has no syntax errors according to the compiler I'm using, but it doesn't produce the ouput I need.


It prints out this:

*
**
***
****
*****
******
*******

I need it to print out this very thing but I need it to be aligned on the right side so.... on the first line I would have 6 spaces then an * and on the second line have 5 spaces then ** and so on up to 0 spaces and 7 *.

....and I'm having to do it with either a "for" or a "while" loop.


See More: For/While Loops for patterns

Report •

#1
March 6, 2010 at 18:12:06
 for (l = 6; l > i; l--)
 {
    cout << " ";
}


Report •
Related Solutions


Ask Question