title: Creating a C++ text pyramid, from user input
body: <p>I am writing this for a C++ course on Udemy, and this is the section 10 assignment. So I've gone back and forth from the lessons and previous code where I learned how to use string methods etc, and I just can't seem to make sense of why it doesn't work. The logic looks on point to me.</p>
  
  <p>My goal here is to create a program that can take user input and create a pyramid with it, like so...</p>
  
  <pre><code>      A     
       ABA
      ABCBA     
     ABCDCBA   
    ABCDEDCBA  
   ABCDEFEDCBA
  ABCDEFGFEDCBA
  </code></pre>
  
  <p>pyra is an empty string where I just add one letter at a time from the user_input string to make the pyramid. It then prints out pyra and the loops backwards through pyra skipping the first letter, to create the mirror effect. Every time the loop goes through it erases a single space from space (which are printed before and after the actual letters are.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main() {
  
    string user_input {}, pyra {""}, space (user_input.length() - 1, ' ');
  
    cout &lt;&lt; "Please enter a sequence of characters... ";
    cin &gt;&gt; user_input;
  
    for (size_t i{0}; i &lt; user_input.length(); ++i) {
  
      pyra = user_input.substr(0, i + 1);
  
      cout &lt;&lt; space &lt;&lt; pyra;
  
      if (pyra.length() == 1) {
        cout &lt;&lt; space;
      } else {
        for (auto j {pyra.length()}; j &gt; 0; --j) {
          cout &lt;&lt; pyra.at(j);
        }
      }
      space.erase(0, 1);
      cout &lt;&lt; endl;
    }
    return 0;
  }
  </code></pre>