title: c++ sort(ascending,descending) integer array
body: <p>So i'm new in C++ and i'm trying some beginner exercises here is the problem : i have to order an integer array in ascending and descending order but every time i try the ascending order there is a 0 appearing out of nowhere inside my array replacing a previous array integer. This is happening only when i use the "ascending order" option. I've tried rearranging the numbers inside the array and changing them but the same thing happens i really can't figure out the problem.I would appreciate some help and i hope my question is not dumb and waste your time.</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int main()
  {
  
  int i,y,choice,temp,am[5]={8,6,10,7,9};
  
  cout&lt;&lt;"Choice 1 : Descending\nChoice 2 : Ascending\n";
  cin&gt;&gt;choice;
  
  if(choice==1)
  {
      for(i=0;i&lt;5;i++)
      {
          y=i+1;
          while(y&lt;5)
          {
              while(am[i]&lt;am[y])
              {
                  temp=am[i];
                  am[i]=am[y];
                  am[y]=temp;
                  y++;
              }
              y++;
          }
      }
  }
  else if(choice==2)
  {
      for(i=0;i&lt;5;i++)
      {
          y=i+1;
          while(y&lt;5)
          {
              while(am[i]&gt;am[y])
              {
                  temp=am[i];
                  am[i]=am[y];
                  am[y]=temp;
                  y++;
              }
              y++;
          }
      }
  }
  else
      cout&lt;&lt;"Error\n";
  
  for(i=0;i&lt;5;i++)
      cout&lt;&lt;"am[i]:"&lt;&lt;am[i]&lt;&lt;"\n";
  
  return 0;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mkspf.png" rel="nofollow">here is what i see in cmd</a></p>