Please help with simple programming. Will upvote answers. I\'m stuck programming
ID: 3751272 • Letter: P
Question
Please help with simple programming. Will upvote answers.
I'm stuck programming a tree in c++.
So far I have:
#include
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;
}
I need to make the program.
1. Prompt the user for the height of the cone of the tree
2. Input the height of the cone from the console into a variable. 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 (it does not loop or ask for new input)
3. Draw the cone part of the tree - the height of the cone is the height entered above
No space between the left side of the console window and the left side of the cone at the base of the cone
No space between the sides of the cone at the peak
4. Draw the base that separates the cone and the trunk with hyphen or minus characters not the underscore character
There will be an even number of dashes
There is NO blank line between the cone and base
There is NO blank line between the base and the trunk
5. Draw the tree trunk
There are NO spaces between the sides of the trunk
The trunk is half the height of the cone - if the height is odd, truncate (this is easy if you remember how integer division (Links to an external site.)Links to an external site. works) - e.g., if the cone height is 5, the truck height is 2
Use only iostream and iomanip functions for I/O and formatting (no stdio)
Explanation / Answer
//C++ program
#include<iostream>
#include<iomanip>
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
{
for (int level = 0; level < height; level++)
{
cout<<setw(height-level)<<"/";
for(int i=0;i<level;i++)
cout<<"__";
cout<<"\";
cout << endl;
}
}
return 0;
}