title: sorting 'age' of names entered then displaying the result
body: <p>I want to sort age in ascending order of respective entered names and then display the list according to that. I have managed to sort them but I can't seem to display the names correctly w.r.t their age.</p>
  
  <p>Here is my code :-</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      char name [5][25];
      int age [5];
      int i;
  
      for (i=0 ; i&lt;5 ; i++)
      {
          cout &lt;&lt; "Enter name " &lt;&lt; i+1 &lt;&lt; "  :   ";
          cin &gt;&gt; name [i];
          cout &lt;&lt; "Enter age     :   ";
          cin &gt;&gt; age [i];
          cout &lt;&lt; endl;
      }
  
      cout &lt;&lt; "\n********** Your entered data **********\n\n";
  
      cout &lt;&lt; "\tName" &lt;&lt; "\t\t" &lt;&lt; "Age\n\n";
  
      for (i=0 ; i&lt;5 ; i++)
      {
          cout &lt;&lt; "\t" &lt;&lt; name [i] &lt;&lt; "\t\t" &lt;&lt; age [i];
          cout &lt;&lt; endl;
      }
  
      int hold;
  
      for (i=0 ; i&lt;5 ; i++)
      {
          for (int j=0 ; j&lt;5 ; j++)
          {
              if (age [j] &gt; age [j+1])
              {
                  hold = age [j];
                  age [j] = age [j+1];
                  age [j+1] = hold;
              }
          }
      }
  
      cout &lt;&lt; "\n\n******* Sorted data (w.r.t age) *******\n\n";
  
      cout &lt;&lt; "\tName" &lt;&lt; "\t\t" &lt;&lt; "Age\n\n";
  
      for (i=0 ; i&lt;5 ; i++)
      {
          cout &lt;&lt; "\t" &lt;&lt; name [i] &lt;&lt; "\t\t" &lt;&lt; age [i];
          cout &lt;&lt; endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Problem is with the last <code>for</code> loop. Can anyone of you help me implementing this logic?</p>