In: Computer Science
C++ In this lab, you will ask the user to design a leaning pyramid. The pyramid will either lean left or right. Start by asking the user how tall they want the pyramid to be. Then ask the user if they want the pyramid to lean left or right. You should then display a pyramid that meets the requirements. (See below for examples). YOU MUST use nested loops for your solution for ANY credit. Sample Run #1: Enter a pyramid height: 4 Do you want to make your pyramid lean left or right? (L for left, R for right): R * ** *** **** Sample Run #2: Enter a pyramid height: 6 Do you want to make your pyramid lean left or right? (L for left, R for right): L * ** *** **** ***** ******
#include <iostream>
using namespace std;
int main()
{
int rows,i,j;
char c;
cout<<"Enter a pyramid height: : ";
cin>>rows;
cout<<"Do you want to make your pyramid lean left or right?
(L for left, R for right): ";
cin>>c;
// if user selects left angle triangle
if(c=='L'||c=='l'){
//iteraing for rows
for( i=0;i<rows;i++){
//printing the stars from 0..i
for( j=0;j<=i;j++){
cout<<"* ";
}
cout<<endl;
}
}
else{
for (i = 1; i <= rows; i++)
{
//printing spaces
for (j = 1; j <= rows - i; j++)
{
cout << " ";
}
//printing stars
for (j = 1; j <= i; j++)
{
cout <<"* ";
}
cout << endl;
}
}
return 0;
}
Note : If you like my answer please rate and help me it is very Imp for me