61.1k views
4 votes
c++ This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches triangleHeight. Output a space after each user-specified character, including after the line's last user-specified character. (2 pts) Example output for triangleChar = % and triangleHeight = 5:

1 Answer

1 vote

Answer:

see explaination

Step-by-step explanation:

Program code:

//Include the needed header

#include <iostream>

using namespace std;

//Method main()

int main()

{

//Declare a variable for triangle character

char triangleCharacter;

//Declare a variable for triangle height

int triangleHeight;

//Prompt the user for traingle character

cout<<"Enter a character:";

//Read triangle character

cin>> triangleCharacter;

//Prompt the user for traingle height

cout<<"Enter traingle height:";

//Read triangle height

cin>> triangleHeight;

//Display first line

cout << triangleCharacter << " " << endl;

//Display second line

cout << triangleCharacter << " " << triangleCharacter << " " << endl;

//Display third line

cout << triangleCharacter << " " << triangleCharacter << " " << triangleCharacter << " " << endl;

//Return

return 0;

See attachment for program output

c++ This program will output a right triangle based on user specified height triangleHeight-example-1
User Jokeyrhyme
by
3.4k points