Kayla P.

asked • 10/08/22

Help with 4.28 LAB*: Program: Drawing a half arrow C++

Write a program that outputs a downwards facing arrow composed of a rectangle and a right triangle. Arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. Input the arrow base height (int) and width (int). Draw a rectangle using asterisks (height x width). Hint: use a nested loop in which the inner loop draws one row of *s, and the outer loop iterates a number of times equal to the height. Submit for grading to confirm two tests pass.

Ex: If input is:

6 4

Sample output is:

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

Step 2 (3 pts). Input the arrow head width and draw a right triangle. Hint: use a nested loop. Submit for grading to confirm four tests pass.

Ex: If input is:

4 3 4

Sample output is:

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

Step 3 (4 pts). Modify the program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue inputting the arrow head width until the value is larger than the arrow base width. Submit for grading to confirm all tests pass.

Ex: If input is:

4 3 3 2 4

Sample output is:

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

This is my code:


#include <iostream>

using namespace std;


int main() {

int arrowBaseHeight = 0;

int arrowBaseWidth = 0;

int arrowHeadWidth = 0;

int i = 0;

int j = 0;

int x = 0;

int y = 0;

cin >> arrowBaseHeight;


cin >> arrowBaseWidth;


cin >> arrowHeadWidth;

for (i = 0; i <= arrowBaseHeight; i++){

for (j = 0; j < arrowBaseWidth; j++){

cout << "*";

}

cout << endl;

}

for (x = arrowHeadWidth; x > 0; x--){

for (y = 0; y < x; y++){

cout << "*";

}

cout << endl;

}


return 0;

}


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.