I've got a rather long function that will take the size of a triangle print it with stars and give the user the option of whether or not they want stars printed inside the triangle, and the orientation (point up or down).  I was hoping for some general refactoring methodologies I could apply.Every permutation is possible for inverted/filled, inverted/not filled, etc.  What are some good general methods I can apply here to get some more code reuse?void Triangle::Print(string direction, string fill){    string starWithSpace = * ;    for (int i = leg1 - 1, j = 1; i >= 0; i--, j++, j < i)    {        if (direction == vertical)        {            cout << string(i, ' ');            if (fill == yes)            {                int repeat = 0;                while (repeat < j)                {                    cout<< starWithSpace;                    repeat++;                }            }            else if (fill == no)            {                if (j * 2 - 3 < 0)                {                    cout << *;                }                if ( j > 1 && i >= 1)                {                    cout << *;                    cout << string(((j * 2 - 3) < 0) ? 1 : j * 2 - 3, ' ');                    cout << *;                }                if (i == 0)                {                    int repeat = 0;                    while (repeat < leg1)                    {                        cout << starWithSpace;                        repeat++;                    }                }            }            cout << \n;        }        else if (direction == inverted)        {            //print bottom line            if (j == 1)            {                int repeat = 0;                while (repeat < leg1)                {                    cout << starWithSpace;                    repeat++;                }            }            cout << string(j - 1, ' ');            if (j != 1 && fill == yes)            {                int repeat = 0;                while (j >1 && repeat < i +1)                {                    cout << starWithSpace;                    repeat++;                }            }            else if (fill == no && j!= 1)            {                int skipFactor = i * 2 - 1;                cout << *;                cout << string(skipFactor > 0 ? skipFactor: 1, ' ');                if (i != 0)                {                    cout << *;                }            }            cout << \n;        }    }    cout << \n;}
Printing a triangle of stars
c++;console;formatting