Hollow Triangle

Hello! I am trying to write a program that prints a triangle, with the size based on the base value entered by the user. I got the triangle to print, but now I need to make it hollow, so the symbols create just the outline of a triangle. However, I'm not sure how to adjust my code to do this.

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
 //This program prints a triangle shape based on the user's inputs
#include <iostream>
#include <iomanip>

using namespace std;

//Variables
int base;
int i,j,k;
char symbol;
char no;
char q;

int main ( )
{
    //Get user inputs for triangle size
    cout << "Enter a value to represent the base of a triangle shape (not to exceed 80): ";
    cin >> base;
    base++;
    
    //Get user inputs for symbol used to make triangle
    cout << "Enter the character to be used to generate the filled-in triangle shape (for eg., #, * $): ";
    cin >> symbol;
    cout << "\n";
    
    //Create triangle shape based on inputs
    for(i = 0; i < base; i++)
    {
        for (j = base; j > i; j--)
            cout<<' ';
        
        for (k = base; k <= 2*i; k++)
            cout<<symbol;
        
        cout << endl;
    }
    
    //End the program
    cout << "Do you want to quit the program? (type n for no or q to quit): ";
    cin >> no >> q;
    while (no == 'n');
    
}
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Create triangle shape based on inputs
    for(i = 0; i < base; i++)
    {
        for (j = base; j > i; j--)
            cout<<' ';
        
        for (k = base; k <= 2*i; k++)
        {
            if(k != base && k != 2*i && i != base-1)
                cout << ' ';
            else
                cout<<symbol;
        }
        
        cout << endl;
    }


Enter a value to represent the base of a triangle shape (not to exceed 80): 21
Enter the character to be used to generate the filled-in triangle shape (for eg., #, * $): @

 
            
           @
          @ @
         @   @
        @     @
       @       @
      @         @
     @           @
    @             @
   @               @
  @                 @
 @@@@@@@@@@@@@@@@@@@@@
Do you want to quit the program? (type n for no or q to quit): 
Topic archived. No new replies allowed.