Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- // initialize input vars
- int trunkHeight;
- int trunkWidth;
- int leavesWidth;
- //trunk height input
- cout << "Enter trunk height: ";
- cin >> trunkHeight;
- cout << endl;
- //trunk width input
- cout << "Enter trunk width: ";
- cin >> trunkWidth;
- while(trunkWidth%2 == 0)
- {
- cout << endl;
- cout << "Please enter an odd number for the width: ";
- cin >> trunkWidth;
- }
- cout << endl;
- //leaves width input
- cout << "Enter leaves width: ";
- cin >> leavesWidth;
- while(leavesWidth%2 == 0)
- {
- cout << endl;
- cout << "Please enter an odd number for the width: ";
- cin >> leavesWidth;
- }
- //submission wanted these newlines
- cout << endl;
- cout << endl;
- // Print leaves
- for(int y = 0; y < leavesWidth/2 + 1; y++)
- {
- //preceding spaces
- for(int x = 0; x < (leavesWidth / 2) - y; x++)
- {
- cout << " ";
- }
- //Leaves themselves
- for(int z = 0; z < (y * 2) + 1; z++)
- {
- cout << "*";
- }
- cout << endl; // new layer of the leaves
- }
- //printing the trunk
- for(int i = 0; i < trunkHeight; i++)
- {
- int widthOfSpaces = (leavesWidth - trunkWidth) / 2; // how many spaces preceding the trunk
- for(int k = 0; k < widthOfSpaces; k++)
- {
- cout << " ";
- }
- //trunk pieces
- for(int j = 0; j <trunkWidth; j++)
- {
- cout << "*";
- }
- //start a new row of the trunk
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement