title: Sorting an array replaces values with zeros
body: <p>The problem starts near the very bottom of the array. I print percent[x] values to make sure they are there, and then after the sort, three of them are filled with zeros. I've been looking around for awhile but I can't find anything.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      int votes[5][4]={192,48,206,37,
                       147,90,312,21,
                       186,12,121,38,
                       114,21,408,39,
                       267,13,382,29};
  
      char cand[4]={'A','B','C','D'};
  
      int row_totals[5];
      int col_totals[4]; //This is left for you to do
                         //see code below to see how
                         //row_totals were calculated.
  
      int total_votes; 
                          //use a for loop to calculate 
                       //using either row_totals or col_totals   
  
  
      float percent[4]; //use a for loop to calculate based on
  
      int swap;  //total_votes and col_totals
  
      //be sure to print the totals for the candidates
  
  
      //at the end, you will need to sort the percent array
      //bringing along the values from the cand array. That is
      //if a swap is made in the percent array, do the same 
      //swap in the cand array.
  
      //then if percent[3] is greater than 50, declare cand[3] the winner
      //if percent[3] is not greater than 50, declare a run-off
      //between cand[2] and cand[3]
  
      int row,col;
  
      for(row=0;row&lt;=4;row++)                     // used to find the row total
      {
          row_totals[row]=0;
  
          for(col=0;col&lt;=3;col++)
          {
              row_totals[row] += votes[row][col];
          }
      }
  
      for(col=0; col &lt;=3; col++)
      {
          col_totals[col]=0;
          for(row =0; row &lt;= 4; row++)            // used to find the column total
      {
            col_totals[col] += votes[row][col];
          }
      }
  
      for(row =0; row&lt;=4; row++)
      {
          total_votes += row_totals[row]; //finds the total amount of the votes
      }
  
  
      printf("            Candidate   Candidate   Candidate   Candidate   Total\n");
      printf(" Precinct:       A           B           C           D       Votes\n");  
      for(row=0;row&lt;=4;row++)
      {
          printf("%6d",row+1);
          for(col=0;col&lt;=3;col++)
          {
              printf("%12d",votes[row][col]);
  
          }
          printf("%11d\n",row_totals[row]);
  
      } 
  
  
  
  
  printf("Total\nVotes:");
      for(col=0; col&lt;=3; col++)
      {
          printf("%12d", col_totals[col]);
  
      }
      printf("       %d", total_votes);
      printf("\nPrecentage:");
      for(col=0; col &lt;= 3; col++)
      {
          percent[col] = (col_totals[col] / (double)total_votes);  //calculates percentages
          printf("%11f", percent[col]);
      }
  int x,y;
      for(x=0; x&lt;=3; x++)
      {
  
  printf("\n%f", percent[x]);
      }
  
  
  
   for(x=0; x&lt;3; x++)
      {
          for(y=0;y&lt;(3-x); y++)
          {
              if(percent[y] &gt; percent[y+1])
              {
                  swap = percent[y];
                  percent[y] = percent[y+1];
                  percent[y+1]= swap;
  
              }
          }
      }
  
      for(col=0; col&lt;4; col++)
      {
  
  printf("\n%f", percent[col]);
      }
      return 0;
  </code></pre>