inverted triangle

Mar 2, 2013 at 3:31am
In my C++ class we have to write a program that makes a hollow triangle that looks like this
. . . . .*
. . . .*.*
. . .*. . .*
. .*. . . . .*
.*. . . . . . .*
***********

which I was able to do with this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>

using namespace std;

int main()
{
    int base;
    int rowCount=0;
    int spaceCount=0;
    int innerSpace=0;
    int lastRow=0;
    char symbol;

    cout <<"Enter a value to represent the base of a triangle shape (not to exceed 80) ";
    cin>>base;

    while (!cin || base>80)
    {
        cout <<"Enter a value to represent the base of a triangle shape (not to exceed 80) ";
        cin>>base;
    }

    if (base%2==0)
        base++;

    cout<< "Enter the charater to be used to generate the triangle shape ";
    cin >> symbol;

    while (rowCount< (base/2))
    {

        spaceCount=rowCount;
        while (spaceCount<base/2)
        {
            cout<<" ";
            spaceCount++;
        }
        cout<<symbol;



        innerSpace=rowCount*2-1;
        while (innerSpace>=1 && innerSpace<base)
        {
            cout<<" ";
            innerSpace--;
        }
        if (rowCount>0 &&rowCount<base)
            cout<<symbol<<endl;

        else
            cout<<endl;


        rowCount++;

        if (rowCount==base/2)
            {
                lastRow=1;
            while (lastRow<=base)
        {
            cout<<symbol;
            lastRow++;
        }
            }
           // else
                //return 1;

    }
return 0;
}


now I have to invert it. I got the first part okay but I am having trouble with the inner spacing. here is what I have so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>

using namespace std;

int main()
{
    int base=11;
    int rowcount=0;
    int spacecount=0;
    int innerSpace=0;
    int firstRow=0;

    while (rowcount<=base/2)
    {
        spacecount=1;
         while (spacecount<=rowcount)
            {
             cout<<".";
             spacecount++;
            }

            cout<<rowcount<<endl;

        innerSpace=rowcount;
        while (innerSpace<base - rowcount + 1)
        {
            cout<<".";
            innerSpace++;
        }






            rowcount++;
        }
return 0;
}


the inner spacing is not working at all. If you comment out the innerSpace loop the beginning spacing works.
Last edited on Mar 2, 2013 at 3:37am
Mar 2, 2013 at 3:39am
Invert it? Like, replace spaces with stars and stars with spaces? What do you mean by invert?

Original:
     *
    * *
   *   *
  *     *
 *       *
***********
What is the new one supposed to look like? (I used the [output] tags to keep the alignment)
Last edited on Mar 2, 2013 at 3:42am
Mar 2, 2013 at 3:41am
flip it upside down and still centered not right of left justified.
Mar 2, 2013 at 3:43am
Could you not take your original program and just go backwards, printing the last line first, etc?
Mar 2, 2013 at 3:45am

*********** 
 *       *
  *     *
   *   *
    * *
         *
Last edited on Mar 2, 2013 at 3:48am
Mar 2, 2013 at 3:46am
I hope that's the output you're getting and not the output you want.
Mar 2, 2013 at 3:50am
no that didnt sem to work and not I am trying to manually input the output this is what I am getting right now with what I have and the innerspace commented out

0
.1
..2
...3
....4
.....5

Process returned 0 (0x0)   execution time : 0.082 s
Press any key to continue.

Mar 2, 2013 at 3:55am
I thought you wanted it upside-down?
Mar 2, 2013 at 3:58am
I do the numbers are my row count just so I can see where things are and the . so far are the spaces from the right to what ever symbol is picked. I have not figured out how to get the inner spacing and the right side symbol. that is the same way I started the regular triangle.
Last edited on Mar 2, 2013 at 3:59am
Mar 2, 2013 at 4:11am
Ah - can't you use the same math as from the previous code, but flipped?
Mar 2, 2013 at 4:26am
the math I used in the other one was innerspace=rowcount*2-1
Topic archived. No new replies allowed.