title: adding digits in an array c++
body: <p>I'm new to C++ and i was trying to understand how to work with arrays. The idea I have is:</p>
  
  <ol>
  <li>I wanted a user to input an array, the program to output the
  array </li>
  <li>Double all the values in the array and output that </li>
  <li>And for each of the doubled values, add the digits of the doubled number
  (1 digit number would remain the same), then output the new numbers as
  well.</li>
  </ol>
  
  <p>(e.g. if the array was [5, 6, 7, 8], the doubled values would be [10, 12, 14, 16] and then you would add each values digits like, [1+0, 1+2, 1+4, 1+6] to get [1, 3, 5, 7].</p>
  
  <p>I put my code to show my progress, feel free to point out any errors along the way!</p>
  
  <p>Any help is appreciated!</p>
  
  <p>p.s. The nested loop didn't work :(</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int maxNum;
  int num[20];
  
  int main()
  {
    cout &lt;&lt; "Enter an Array" &lt;&lt; endl;
    for (int i=0;i&lt;20;i++)
    {
        cin &gt;&gt; num[i];
        maxNum++;
        if (num[i]==-1)
        break;
    }
  
    cout &lt;&lt;"Your array is: " &lt;&lt; endl;
  
    for (int i=0;i&lt;maxNum-1;i++)
    cout &lt;&lt; num[i];
  
    cout &lt;&lt; endl;
  
      cout &lt;&lt; "Your doubled array is:" &lt;&lt; endl;
  
      for (int j=0;j&lt;maxNum-1;j++)
      {
      num[j]*=2;
      cout &lt;&lt; num[j];
      }
  
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "When the digits of each seat are added..." &lt;&lt; endl;
  
      for (int k=0;k&lt;maxNum;k++)
      {
         for (int l=0;l&lt;maxNum;l++)
         {
             int sum[20];
             while (num[k]!=0)
             {
             sum[l]=sum[l]+num[k]%10;
             num[k]=num[k]/10;
             }
         }
         cout &lt;&lt; sum[l];
      }
      cout &lt;&lt; endl;
  }
  </code></pre>