title: c++ how count characters from user input?
body: <p>I have to ask the user for their name and the count the letters in each name they enter.</p>
  
  <p>This is my code and it works for two names but I was wondering what if the user puts three names. How can I improve this or I want to know a better way to do this.</p>
  
  <pre><code>int x1 = 0;
  int x2 = 0;
  char name;
  cout &lt;&lt; "What is your name? : ";
  while (cin.get(name) )
  {
  
      if (name == 32)
      {
  
          x2 = x1;
          x1 = 0;
  
      }
      else if (name == '\n')
      {
          x1 -= 1;
          break;
      }
      x1++;
  }
  cout &lt;&lt; x2 &lt;&lt; " " &lt;&lt; x1 &lt;&lt; endl;
  </code></pre>