Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1 Task 1 is to copy and paste the code below into the project. This code asks the user for a height and then

Task 1
Task 1 is to copy and paste the code below into the project. This code asks the user for a height and then prints out a sideways pyramid. For example, the goal is to produce this output with a height of 4(although the actual code will be slightly wrong--we'll fix that in Task 2).// Copy/paste (or type) your code here
// Lab 1 template code, CS 141
// Write and run the tests for the individual problems one at a time.
//
#include
#include // for setw() and setfill()
using namespace std;
// main is where our program begins
int main(){
// Create a height variable and get the input from the user
int height;
cout << "Enter the height: ";
cin >> height;
// Use a while loop to count up from 1 to the height
int level =1;
while (level <= height){
// Note that "\\" just outputs one back-slash: \ is a special character in C++,
// so we just repeat it to clarify we really mean a backslash
// endl starts for "end line" and will output a new line for us.
// As explained in Task 2, setw specifies how many characters
// should be output when we display the backslash
cout << setw(level-1)<<"\\"<< endl;
// Add one to level
level++;
}
// Now start at height, and count down to 1
level = height;
while (level >=1){
cout << setw(level-1)<<"/"<< endl;
// Subtract one from level
level--;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How does switched Ethernet differ from traditional Ethernet?

Answered: 1 week ago

Question

5. Identify and describe nine social and cultural identities.

Answered: 1 week ago

Question

2. Define identity.

Answered: 1 week ago

Question

4. Describe phases of majority identity development.

Answered: 1 week ago