void triangle(ostream &outs, unsigned int m, unsigned int n)
{
if ( m <= n)
{
int NumberOfLines = (2 * (( n - m) + 1));
int Mid = (NumberOfLines / 2);
for (int i = 0; i < NumberOfLines; i++)
{
if (i < Mid)
{
for (int j = i; j < n; j++)
outs << "*";
}
else
{
for (int j = 0; j < (m + (i - Mid)); j++)
outs << "*";
}
outs << endl;
}
}
else
outs << "Value m cannot be greater than n." << endl;
}

it comes out opposite of what i want it to do.
it looks like this.
****
***
**
**
***
****
but I want it to look like this.
**
***
****
****
***
**

Edited 7 Years Ago by Nick Evan: fixed tags

but I want it to look like this.
**
***
****
****
***
**

1) Make a function called : printStar(int num);

Where it prints num of stars :

For example a call to printStar(4) would produce :
****

or a call to printStar(2) would produce : ***

After you make that function you can make your loop start at
2 end at 4 then decrease to 2.

So

for(int i = 2; i <= 4; i++)
         printStars(i); //prints i amount of stars with a newline
for(int j = 4; j >= 2; --j)
     printStars(j); //prints j amount of starts with a newline

Then thats it!

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I actually figured it out. But I need to use recurrsion, and it's not coming to me. Unless what I have is considered recursion, but I need to call back triangle.

void triangle(ostream &outs, unsigned int m, unsigned int n){
     if (m <= n){
         for (int i = m; i <= n; i++){
             for (int j = 1; j <= i; j++)
                 cout << '*';
                 cout << endl;
                 }
                 }
         for (int i = n; i >= m; i--){
             for (int j = 1; j <= i; j++)
                 cout << '*';
                 cout << endl;
                 }
}

Edited 7 Years Ago by Nick Evan: Added code-tags

Tthats not recursion.

Heres a small example, counting down from a number to 1.

void recur(int x){
if(x == 0) return;
cout<<x;
void recur(x-1);
}

Edited 7 Years Ago by DaBunBun: n/a

This article has been dead for over six months. Start a new discussion instead.