title: If statement ignoring zero?
body: <p>This program reads two files and stores them in two arrays. array1 is the data and array2 is the type that corresponds to it. ex array1: 183, 183, 182, 195.3, 187  array2: 1, 1, 1, 2, 2 it sets the repeated numbers in the array1 to 0 and sets the corresponding number in array2 to zero. Ex: array1: 0, 0, 182, 195.3, 187 array2: 0, 0, 1, 2, 2 Then it should ignore the zeros in the for loop and calculate the sum for all the numbers of the same type. Ex: (for some reason called it mean) mean[2] = 195.3 + 187 It seems to be ignoring atleast one of the if statements which has it > .5 and going to the else statement when it encounters a zero. Any ideas?   </p>
  
  <p>Example data from file (not complete data), as soon as it sees 182.6000061 next to each other it sets those to zero and the corresponding number in the array2, yet it ignores one of the if statement and goes to the else statement. Output is 2822.799, 881.400, 1997.8, ect. Where the first value should be closer to 6000.  </p>
  
  <p>input data into array1: 182.6000061
  183
  182.6000061
  182
  177.8000031
  183.3999939
  183
  180.6000061
  147.6000061
  166.6000061
  168
  182
  181.6000061
  164.1999969
  180.3999939
  177.3999939
  177.6000061
  182.6000061
  182.6000061
  181.6000061
  179.8000031
  160
  177.3999939
  181.3999939
  183.1999969
  183.1999969
  182.8000031
  181.3999939
  179.6000061
  182.1999969
  183.8000031
  176.8000031</p>
  
  <p>input data into array2: 2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2912
  2979
  2979
  2979
  2979
  2979
  2979
  2979
  2979
  2979</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
  {
      FILE *fp;
      float array1[1000] = {0}, array2[1000] = {0}, mean[1000] = {0}, average[1000] = {0}, counter[1000] = {0}, range[1000] = {0}, upper[1000] = {0}, lower[1000] = {0};
      int a, h, i, r, j = 0, pos, found = 0, extrinsic[1000] = {0};
      int b=0;
      int linect = 1;
      char buf[128];
  
      i = 0;
      j = 0;
      fp = fopen("data.txt", "r");
  
      if(fp == NULL)
      {
          puts("Cannot open file for reading");
          scanf("%d", &amp;a);
          exit(EXIT_FAILURE);
      }
  
      while( linect &lt; 1000 ) 
      {
          fgets(buf, sizeof(buf), fp);
          sscanf(buf, "%f", &amp;array1[i]);
          //printf("Set %d - 1st: %f\n", linect, array1[i]);
          linect++;
          i++;
      }
      fclose(fp);
  
  
      linect = 0; //reads lot data file and puts it in array2
      i = 0;
      fp = fopen("lot_numbers.txt", "r");
      if(fp == NULL)
      {
          puts("Cannot open file for reading");
          scanf("%d", &amp;a);
          exit(EXIT_FAILURE);
      }
      while( linect &lt; 1000 ) 
      {
          fgets(buf, sizeof(buf), fp);
          sscanf(buf, "%f", &amp;array2[i]);
          // printf("Set %d - 1st: %f\n", linect, array2[i]);
          linect++;
          i++;
      }
  
  
      for (i = 0; i &lt; 999; i++) //searches array sets repeated points to zero
      {
          if (array1[i] == array1[i+1])
          {
              array1[i] = 0;
              array2[i] = 0;
          }
      }
      for (i = 0; i &lt; 99; i++)   //searches array
      {
          if (array2[i] &gt; .5 &amp;&amp; array2[i] &lt; 50000)
          {
              if (array2[i] == array2[i+1])
              {
                  if (array1[i] &gt; .5 &amp;&amp; array1[i] &lt; 500){  //ignores zeros and junk data 
                      mean[j] = mean[j] + array1[i];
                      counter[j]= counter[j] + 1;
                  }
              }
              else {
                  average[j] = mean[j]/counter[j];
                  range[j] = average[j] * 0.1;
                  upper[j] = average[j] + range[j];
                  lower[j] = average[j] - range[j];
                  j++;
              }
          }
      }
      j = 0;
      while (j &lt;10){
          printf("\n%f", mean[j]);
          j++;
      }
      scanf("%d", &amp;a);
  
      return 0;
  }
  </code></pre>