title: Name format Lab
body: <p><a href="https://i.stack.imgur.com/QZU0F.png" rel="nofollow noreferrer">CLICK HERE TO SEE THE IMAGE PROBLEM</a></p>
  <p>C++ - I'm having a big problem with my code and I don't understand where I did the mistake because I'm not getting the result that I want for example the 1st output that problem is asking me :(</p>
  <p><a href="https://i.stack.imgur.com/FeIXq.png" rel="nofollow noreferrer">My FULL CODE</a></p>
  <p><a href="https://i.stack.imgur.com/F2NnA.png" rel="nofollow noreferrer">Outputs that I'm getting wrong</a></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main() {
  
     string firstName, middleName, lastName, theName;
     
     getline(cin, theName);
     
     int findN = theName.find(&quot; &quot;);
     firstName = theName.substr(0, findN);
     int findN2 = theName.find(&quot; &quot;, findN + 1);
     if (findN2 != string::npos){
        middleName = theName.substr(findN2 + 1, findN2 - findN - 1);
        lastName = theName.substr(findN2 + 1, theName.length() - findN2 - 1);
        cout &lt;&lt; lastName &lt;&lt; &quot;, &quot; &lt;&lt; firstName[0] &lt;&lt; &quot;.&quot; &lt;&lt; middleName[0] &lt;&lt; &quot;.&quot; &lt;&lt; endl;
        }
        else {
           lastName = theName.substr(findN + 1, theName.length() - findN - 1);
           cout &lt;&lt; lastName &lt;&lt; &quot;, &quot; &lt;&lt; firstName[0] &lt;&lt; &quot; . &quot; &lt;&lt; endl;
           }
     
  
     return 0;
  }
  </code></pre>