title: My game of Master mind keeps adding after every loop
body: <p>The program works fine but when it loops which is at the begginging where the comment loop is. The counter adds it instead of reseting after every loop. Example: Turn 1: You have 1 correct in the right spot. Then if i enter in the same numbers again on Turn 2 i would get: You have 2 correct in the right spot. And it would keep adding on from there.</p>
  
  <pre><code> class Mastermind 
          {
              public static void main (String[] args)
              {
                  //Welcome
                  System.out.println ("Welcome to Matthew's game of Mastermind!");
                  //Variable
                  int Tally;
                  int guess1, guess2, guess3, guess4;
                  Scanner Guess = new Scanner (System.in);
                  int[] Secret_code = Mystery();
                  int[] Gameboard = Gameboard (Secret_code);
                  int resultCount = Comparing (Secret_code, Gameboard);
                  int resultCount2 = Comparing2 (Secret_code, Gameboard);
                  //Loop
                   for (Tally = 0; Tally &lt;10; Tally++){
                     //User Input
               System.out.println ("What is the number one peg in my code?");
               guess1 = Guess.nextInt();
               System.out.println ("What is the number two peg in my code?");
               guess2 = Guess.nextInt();
               System.out.println ("What is the number three peg in my code?");
               guess3 = Guess.nextInt();
               System.out.println ("What is the number four peg in my code?");
               guess4 = Guess.nextInt();
               //Array for guess's
               Gameboard = new int [4];
               Gameboard[0] = guess1;
               Gameboard[1] = guess2;
               Gameboard[2] = guess3;
               Gameboard[3] = guess4;
               //result Count 
               for (int i = 0; i &lt; 4; i++) {
               if (Gameboard[i] == Secret_code[i])
                resultCount++;
              }
             System.out.println("You got " + resultCount + " correct in the right spot."); 
             //Result Count 2
             int i = 0;
                for (int e = 0; e &lt; 4; e++) {
                  if (Gameboard[e] == Secret_code[i])
                   resultCount2++;
                  }
                  System.out.println ("You got " + resultCount2 + " correct but in the wrong spot");
                      if (Secret_code[0] == Gameboard[0] &amp;&amp; Secret_code[1] == Gameboard[1] &amp;&amp; Secret_code[2] == Gameboard[2] &amp;&amp; Secret_code[3] == Gameboard[3]){
                      break;
                  }
                  if (Tally &gt; 10){
                      System.out.println ("You have exceeded your 10 tries. You lose. Please play again.");
                      break;
                  }
          }
                  //Goodbye
                  System.out.println ("Thank you for playing.");            
                  //Winner
                  if (Gameboard[0] == Secret_code[0] &amp;&amp; Gameboard[1] == Secret_code[1] &amp;&amp; Gameboard[2] == Secret_code[2] &amp;&amp; Gameboard[3] == Secret_code[3])
                  System.out.println ("You have won this game of Mastermind!");
              }
  
  
              public static int[] Mystery () {
  
                  //Random
                  int secretcode = (int)(6*Math.random()) + 1;
                  int secretcode1 = (int)(6*Math.random()) + 1;
                  int secretcode2 = (int)(6*Math.random()) + 1;
                  int secretcode3 = (int)(6*Math.random()) + 1;
  
                 //Secretcode print
                 //System.out.println (secretcode);      Used this for testing to make sure the codes were being outputted correctly.
                 //System.out.println (secretcode1);
                 //System.out.println (secretcode2);
                 //System.out.println (secretcode3);
  
                 //Array
                 int [] Secret_code;
                 Secret_code = new int [4];
                 Secret_code[0] = secretcode;
                 Secret_code[1] = secretcode1;
                 Secret_code[2] = secretcode2;
                 Secret_code[3] = secretcode3;
  
                  return Secret_code;
          }
              public static int[] Gameboard (int[] Secret_code) {
              //Variable Declaration
              int guess1, guess2, guess3, guess4;
              Scanner Guess = new Scanner (System.in);
  
              //User Guess's
               System.out.println ("What is the number one peg in my code?");
               guess1 = Guess.nextInt();
               System.out.println ("What is the number two peg in my code?");
               guess2 = Guess.nextInt();
               System.out.println ("What is the number three peg in my code?");
               guess3 = Guess.nextInt();
               System.out.println ("What is the number four peg in my code?");
               guess4 = Guess.nextInt();
  
               //Array
               int [] Gameboard;
               Gameboard = new int [4];
               Gameboard[0] = guess1;                             //This puts the user's guess's into an array which just makes it easier to compare with the secret code's array
               Gameboard[1] = guess2;
               Gameboard[2] = guess3;
               Gameboard[3] = guess4;
  
               return Gameboard;
      }
              public static int Comparing (int[] Secret_code, int[] Gameboard){
               int resultCount = 0;
               for (int i = 0; i &lt; 4; i++) {
               if (Gameboard[i] == Secret_code[i])
                resultCount++;
              }
      System.out.println("You got " + resultCount + " correct in the right spot."); 
      return resultCount;
      }
      public static int Comparing2 (int[] Secret_code, int[] Gameboard){
                int resultCount2 = 0;
                int i = 0;
                for (int e = 0; e &lt; 4; e++) {
                  if (Gameboard[e] == Secret_code[i])
                   resultCount2++;
                  }
                  System.out.println ("You got " + resultCount2 + " correct but in the wrong spot");
                  return resultCount2;
      }
      }
  </code></pre>