Using an array in Random Number Guessing Game
<p>i'd like to implement an achievement system to my random number guessing game but i failed to construct a valid logic for it.
i'd like it to have an <strong>achievement system</strong> to detect a 2 or 3 consecutive <strong>CORRECT</strong> answers.</p>

<p>whenever there is a <strong>correct</strong> answer, cons+1(cons is the variable im using for the "consecutive" functionality of my achievement system.</p>

<p>otherwise, cons-1 and life-1.</p>

<p>here's my code below... i know for sure that the error in the logic is because the cons--; and the life--; is in the loop for <strong>SCANNING THE ARRAY</strong> for a match(the array is the one im using to store the 10 two-digit random numbers that will be the basis of the "correctness" of each answer. <strong>My purpose for adding the LOOP is that it will scan the array for a possible match.</strong></p>

<p>NOTE: Thank you advance for your help!</p>

<p>here's my code:</p>

<pre><code>public void cmpans()
{
    String txget;
    txget=gametext.getText();
    String pars;
    int ans;
    pars=gametext.getText();
    ans=Integer.parseInt(pars);

    for(int i=0; i&lt;10; i++)  //this is my "Array Scanner" Loop
    {

        if(ans==arr[i])
        {
            userscore=userscore+10;
            lbscore.setText("Score: "+userscore);
            ck[i].setSelected(true);
            arr[i]=0000;
            cons++;
            gametext.setText("");
            lblives.setText("life: "+life);
            lbcons.setText("cons: "+cons);
        }
        else if(ans!=arr[i])
        {
            cons--;   //this is the cons and life im talking about
            life--;
            if(cons==2)
            {
                lbachieve.setText("You're a GOOD GUESSER!");
                userscore=userscore+20;
            }
            else if(cons==4)
            {
                lbachieve.setText("You're an AMAZING GUESSER!!");
                userscore=userscore+50;
            }
        }
    }gametext.setText("");
</code></pre>
