How to compare two integer passwords using array

UKHeliBob:

 char key = kpd.getKey();

...
 key2 = (key2*10)+key[i];



key is declared as a single char, as is key2, not an array. Leaving that aside, key will have the ASCII value of the key pressed, not the actual (numeric) value. Subtract '0' from it if it is a number to get the actual number of the key pressed but you cannot then put it in key2 as currently declared.

So it should be "int key"? I want to send a 4-digit number, but after trying an if loop, it didnt work.
Can you give me a code as how I should declare and compare the keys i have entered with the password?