I'm stuck with this one. I need help drawing a tree in C++. Weird right? I've posted the parameters below and my response has my code so far.
Write a program that draws a pine tree of a specified height
How tall should the tree be?: 6
Prompt the user for the height of the cone of the tree
Read the height from the keyboard into a variable named height
If the cone height is less than 3 or greater than 15 (3 is okay and 15 is okay), then the program prints an error message and terminates
Test it
a. prompt and read the height
b. test for height being out of bounds
c. draw the base
d. draw the trunk (no spaces between the sides) one half the height of the cone
e. draw the cone
Hints
• Use three for-loops to draw the cone: two loops nested in side an outer loop:
• The outer for-loop moves the cursor from the top of the cone to the bottom; use “level” as the loop control variable and treat “height” as a constant
• Use one nested for-loop to move the cursor from the left edge of the screen to the left side of the cone
• Use the second nested for loop to move from the left side of the cone to the right side of the cone. See the table of escape sequences in chap 2 to see how to draw a back-slash character
• Note that there is not a space between the sides of the cone at the peak
• Use one for-loop to draw the base of the cone
• Note that there is not a blank line between the sides of the cone and the base
• Use two for-loops, one nested inside the other, to draw the trunk
• The outer loop moves the cursor from the top of the trunk to the bottom
• The nested loop moves the cursor from the left edge of the screen to the left side of the trunk
• Note that there is not a space between the two sides of the trunk
This is what I have so far; I don't know where to go with this one; Any guideance is appreciated
#include <iostream>
using namespace std;
int main()
{
int height;
int level;
cout << "Enter the height of the tree: " << endl;
cin >> height;
if (height < 3)
{
cout << "Integer too small " << endl;
exit (0);
}
else if (height > 15)
{
cout << "Integer too large" << endl;
exit (0);
}
else
{
cout << '\\' * level << endl;
}
return 0;
}