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