if(y > 3){
for(x=0;x<1;x++){
attempt[x] = 0;
}
y=0;
}
So, how many times does that loop execute? Which elements of the array are you resetting?
Do your self a favor. Add some #define statements to the top of your code to define some names:
#define BTNCNT 9
#define ATTCNT 2
Then, use these names when you declare arrays:
byte buttons[BTNCNT] = {2,3,4,5,6,7,8,9,10}; //Set buttons to array
byte pass[ATTCNT] = {2,3}; // Set password
byte attempt[ATTCNT]; // Set attempts array
byte state[BTNCNT]; // Make states array
byte oldstate[BTNCNT]; // When button is hit, info added here
This will ensure that all arrays are properly sized.
Then, use these names in loops, and other places, too:
for(x=0; x<BTNCNT; x++)
{
pinMode(buttons[x], INPUT);
}
for(x=0; x<ATTCNT; x++)
{
if(attempt[x] == pass[x]) // <== Fixed these, too
{
Correct();
}
}
Also, think about what are reasonable values for the limit conditions:
if(y > 3)
{
Since this test will be false until y is 4, it means that y=0, y=1, y=2, and y=3 are good values, and that attempt[3] is a good place to write to. As currently structured, it is not. If you tested for y>=ATTCNT, the test would limit the index to the maximum that is valid for the array.
Changing the value associated with ATTCNT from 2 to 4 to 12 then requires no other code changes to create and accommodate larger arrays.