title: Checking for duplicate numbers in a 2D matrix and containing the data into two variables
body: <p>I am trying to check 2D matrix array for the correct numbers and extras on each row and then printing them out only once per correct number/extra.</p>
  <p>I.e. if 34 is twice in jackpot and once in the matrix row it should only record it once.</p>
  <p>Correct numbers are first 7 numbers of jackpot array and the extras are the last 3 numbers.</p>
  <p>Can anyone explain why the Row 2's 1 extra is being eliminated from my current output?</p>
  <p>I am guessing it is because the correct number 34 is already recorded in previous[] and this is then compared to the extra 34 and thus extra is substracted by 1.</p>
  <p>How would one go about fixing this, should I make another array that stores the previous extras or something?</p>
  <p>The correct output:</p>
  <pre><code>Row 1 has 0 correct and 0 extras!
  Row 2. has 1 correct and 1 extras!
  Row 3. has 3 correct and 0 extras!
  Row 4. had 1 correct and 1 extras!
  Row 5. has 1 correct and 0 extras!
  </code></pre>
  <p>My current output:</p>
  <pre><code>Row 1. has 0 correct and 0 extras! 
  Row 2. has 1 correct and 0 extras! 
  Row 3. has 3 correct and 0 extras!
  Row 4. has 1 correct and 1 extras!
  Row 5. has 1 correct and 0 extras!
  </code></pre>
  <pre><code>for (int z = 0; z &lt; NUM_PER_ROW; z++) 
  {
      if (previous[z] == jackpot[k] &amp;&amp; k &lt;= 6) 
      {
          correct -=1;
          break;
      }
      else if (previous[z] == jackpot[k] &amp;&amp; k &gt; 6) 
      {
          extra -=1;
          break;
      }
  }
  </code></pre>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  #define MAX_ROWS 5
  #define NUM_PER_ROW 7
  #define MAX_NUM 40
  
  int doStuff();
  
  int doStuff() 
  {
      int matrix[MAX_ROWS][NUM_PER_ROW] = { 
          { 1,  2,  3,  4,  5,  6,  7}, 
          {30, 38,  6, 34,  4, 39, 30},
          { 9, 37, 32, 27,  9, 39, 17}, 
          { 8, 26,  6, 31, 28, 29, 16}, 
          {33, 21, 19,  7,  9, 19, 30} };
      int jackpot[NUM_PER_ROW + 3] = 
          {20, 37, 22,  9, 34, 28, 34, 24, 26, 29};
      int num = 0, i, j, cnt = 0, temp = 0;
  
      for(i = 0; i &lt; MAX_ROWS; i++) 
      {
          int correct = 0;
          int extra = 0;
  
          for(j = 0; j &lt; NUM_PER_ROW; j++)
          {
              int previous[7] = {0, 0, 0, 0, 0, 0, 0};
  
              for (int k = 0; k &lt; NUM_PER_ROW + 3; k++) 
              {
                  if (matrix[i][j] == jackpot[k]) 
                  {
                      for (int z = 0; z &lt; NUM_PER_ROW; z++) 
                      {
                          if (previous[z] == jackpot[k] &amp;&amp; k &lt;= 6) 
                          {
                              correct -= 1;
                              break;
                          }
                          else if (previous[z] == jackpot[k] &amp;&amp; k &gt; 6) 
                          {
                              extra -=1;
                              break;
                          }
                      }
                      if (k &lt;= 6) 
                      {                       
                          correct += 1;
                      } 
                      else 
                      {
                          extra += 1;
  
                      }
  
                      previous[j] = jackpot[k];
                  }
              }
          }
  
          printf(&quot;Row %d. has %d correct and %d extras! \n&quot;, i + 1, correct, extra);
      }
  
      return 0;
  }
  
  int main()
  {
      int num;
      srand(time(NULL));
  
      doStuff(num);
  
      return 0;
  }
  </code></pre>
  <p>Thank you for your time!</p>