title: Problem to find ID number from min & max values
body: <p>So I am trying to make a simple program that reads integers of values and ID number so the output will be minimum maximum of the value and its maxID minID number. The first integer of the input file will indicate how many more input will be read in loops. My program compiles without any problem and minimum maximum output are correct however,the output of ID numbers are wrong. Could anyone help me with diagnose this issue? Sorry for my silly question, I am new in programming. Thanks.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
  
  int val[100],id[100];
  int i, max, min, size, idmax, idmin,minindex,maxindex;
  
  printf("Enter how many IDs: ");
  scanf("%d", &amp;size);
  
  printf("Enter ID numbers and values:\n");
  for(i=0; i&lt;size; i++)
  {
      scanf("%d %d", &amp;id[i], &amp;val[i]);
  }
  
  
  max = min = val[0];
  
  for(i=1; i&lt;size; i++)
  {
      if(val[i] &gt; max)
      {
          max = val[i];
          maxindex = i;
          for(i=0;i&lt;size;i++){
            if(id[i]==maxindex){
              idmax=id[i];
            }
          }
        }
  
      if(val[i] &lt; min)
      {
          min = val[i];
          minindex = i;
          for(i=0;i&lt;size;i++){
            if(id[i]==minindex){
              idmin=id[i];
            }
          }
      }
  }
  
  printf("Max number = %d with ID number = %d\n", max, idmax);
  printf("Min number = %d with ID number = %d\n", min, idmin);
  
  return 0;
  </code></pre>
  
  <p>}</p>