We have a project that simulate the function of an atm. the user must enter a pincode and it will be masked with an asterisk. the input pincode must be equal to the default pincode that is stored in an array. My program can masked the input pincode with an asterisks, the only problem is that even if the input pincode is the same with the default pincode, it still output incorrect. what must be the problem? here is my code:
void checkPword()
{
char defaultPin[4] = "1234";
char inputPin[4] = "";
clrscr();
for (int cnt = 0; cnt <= 3; cnt++)
{
cout << "*";
inputPin[ctr];
}
if (defaultPin[0] == inputPin[0] && defaultPin[1] == inputPin[1]
&& defaultPin[2] == inputPin[2] && defaultPin[3] == inputPin[3])
{
clrscr();
cout << "pincode is correct";
}
else
{
clrscr();
cout << "pincode is incorrect";
}
}
"1234"actually contains five characters. You can't forget the terminating'\0'. This means that you are writing beyond the limits of thedefaultPinarray.inputPin[ctr];supposed to do?getch()toinputPin, is it thatinputPin[cnt] = getch();?