Question

In: Computer Science

C++ In this lab, you will ask the user to design a leaning pyramid. The pyramid...

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

*     
**    
***   
****  
***** 
******

Solutions

Expert Solution

#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


Related Solutions

A, B:   Design and Implement a C# windows form application to ask the user for 10...
A, B:   Design and Implement a C# windows form application to ask the user for 10 integer numbers, sort them in ascending order and display the sorted list. Use bubble sort technique to sort the array elements and do not use any built-in sort method to sort the array elements.                                                        [02] C:    Test and evaluate your program by inputting variety of values.
Design a program (in C++)to calculate the stock purchasing and selling transactions. 1. ask the user...
Design a program (in C++)to calculate the stock purchasing and selling transactions. 1. ask the user to enter the name of the stock purchased, the number of share purchased, and the price per share purchased 2. assume the buyer pays 2% of the amount he paid for the stock purchase as broker commission 3. assume that the buyer sold all stocks. Ask the user to enter the price per share sold. 4. assume the buyer will pay another 2% of...
In C# When the user enters an invalid value, ask the user to repeatedly enter the...
In C# When the user enters an invalid value, ask the user to repeatedly enter the value until a valid value has been entered. Gender must be ‘M’ or ‘F’. Residency must be ‘I’ or ‘O’. Existing Code: using System; public class Student {   public int credit;   public String firstname, lastname, gender, residency, edate;   public void input()   {     Console.WriteLine("\nWelcome to the Continental University Registration System!"); Console.WriteLine("\nEnter data about a student"); Console.Write("First Name: "); firstname = Console.ReadLine(); Console.Write("Last Name: "); lastname...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate the average score and scores below 60. Then display the average score and number of scores below 60
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
[C#] Randomly generate two numbers that user chooses and then ask the user what the answer...
[C#] Randomly generate two numbers that user chooses and then ask the user what the answer is when some operator is applied. If user is correct, they will be congratulated. If they are wrong, they will be given the correct answer. This should be repeated based on how many times is chosen by user. I have the code which will do the following below: User wants to know the answer to x % y, What is smallest value of x:...
Ask the user for a filename, then ask the user for a line of text. Write...
Ask the user for a filename, then ask the user for a line of text. Write the line of text the filename specified by the user. The filename may be absolute or relative to the project directory.
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT