I've tried this method but the problem is that if the programme reaches the near value faster than the exact value, the near value increases by 1 and makes the near match being calculated wrongly.
e.g.
code = 1 2 3 4
guess = 4 5 6 4
As the program compares the 1st "4" with the code "1 2 3 4" 1st, near match will be increased by 1 because the exact value increases in the 4th turn, when the 4th "4" in guess matches the 4th "4" in code, which leads to a wrong answer.
Correct ans: Exact: 1, Near: 0
Ans displayed in my program: Exact: 1, Near: 1