SHARE
TWEET

Untitled

a guest Nov 11th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.    // initialize input vars
  6.    int trunkHeight;
  7.    int trunkWidth;
  8.    int leavesWidth;
  9.    
  10.    
  11.    //trunk height input
  12.    cout << "Enter trunk height: ";
  13.    cin >> trunkHeight;
  14.    cout << endl;
  15.    
  16.    
  17.    //trunk width input
  18.    cout << "Enter trunk width: ";
  19.    cin >> trunkWidth;
  20.    while(trunkWidth%2 == 0)
  21.    {
  22.       cout << endl;
  23.       cout << "Please enter an odd number for the width: ";
  24.       cin >> trunkWidth;
  25.    }
  26.    cout << endl;
  27.    
  28.    
  29.    //leaves width input
  30.    cout << "Enter leaves width: ";
  31.    cin >> leavesWidth;
  32.    while(leavesWidth%2 == 0)
  33.    {
  34.       cout << endl;
  35.       cout << "Please enter an odd number for the width: ";
  36.       cin >> leavesWidth;
  37.  
  38.    }
  39.    
  40.    
  41.    //submission wanted these newlines
  42.       cout << endl;
  43.       cout << endl;
  44.  
  45.  
  46.    // Print leaves
  47.    for(int y = 0; y < leavesWidth/2 + 1; y++)
  48.    {
  49.       //preceding spaces
  50.       for(int x = 0; x < (leavesWidth / 2) - y; x++)
  51.       {
  52.          cout << " ";
  53.       }
  54.      
  55.       //Leaves themselves
  56.       for(int z = 0; z < (y * 2) + 1; z++)
  57.       {
  58.          cout << "*";
  59.       }
  60.    cout << endl; // new layer of the leaves
  61.    }
  62.    
  63.    
  64.    //printing the trunk
  65.    for(int i = 0; i < trunkHeight; i++)
  66.    {
  67.       int widthOfSpaces = (leavesWidth - trunkWidth) / 2; // how many spaces preceding the trunk
  68.       for(int k = 0; k < widthOfSpaces; k++)
  69.       {
  70.        cout << " ";  
  71.          
  72.       }
  73.      
  74.       //trunk pieces
  75.       for(int j = 0; j <trunkWidth; j++)
  76.       {
  77.          cout << "*";
  78.       }
  79.      
  80.       //start a new row of the trunk
  81.       cout << endl;
  82.      
  83.    }
  84.     return 0;
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top