pin error

I have a question for entering an atm number in a simulated atm. What happens is when i enter 1 to enter a pin number it fails on me three times. If I hit a 2 it does what it is supposed to. When I enter something other than a 1 or 2 it also does what it is supposed to.



int dataEntryScreen()
{
//Declare variables
string valid,
pin;
bool found = false;
int pinChoice,
i,
j = 3;
ifstream Input;
//Perform do\while loop to check for correct validation
do
{
//Display the output
cout << "\t\tData Entry Screen";
cout << endl << "1) Enter pin number";
cout << endl << "2) Exit the ATM";
cout << endl << "Please enter a selection: ";
cin >> pinChoice;
//add color to background of data entry screen
//add color to text of data entry screen
system ("Color 3c");
/*
**********************************************
**********************************************
* Check for validation *
* Use while statement *
**********************************************
**********************************************
*/
while (pinChoice < 1 || pinChoice > 2)
{
//Enter a correct choice
cout << "Please reenter 1 or 2: ";
cin >> pinChoice;
//add color to error message
//add color to error message
system ("Color 3a");
}
//If statement if 2 is selected
if (pinChoice == 2)
{
//exit the atm and returning a value
return -1;
}
//end do\while loop
} while (pinChoice > 2 || pinChoice < 1);
/*
*******************************************
*******************************************
* If statement 1 is selected *
* Perform for loop *
*******************************************
*******************************************
*/
for (j = 0; j < 3; j++)
{
//Prompt user to enter pin number
cout << "Please enter your 4 character pin number ";
//Begin another for statement
//input the pin
//Open the file
Input.open("pin.txt");
//Perform error test
if(Input.fail( ))
{
//Display error opening file.
cout << endl << "Error opening input file" << endl;
//add color to error message
//add color to error message
system ("Color 3a");
}
//Determine if false
found = false;
//Input valid
Input >> valid;
//Perform while statement
while (Input && !found)
{
//Perform for loop
for (i = 0; i < 5; i++)
{
//if statement for pin
if (pin[i] != valid[i])
i = 6;
}
//Determine if true with if statement
if (i == 5)
found = true;
//Perform else statement
else
Input >> valid;
}
//Skip a line
cout << endl;
//Close the file
Input.close();
//Clear the file
Input.clear();
//If statement if pin number found
if (found)
//Return a value
return 0;
//Allow only 3 chances for pin to be valid
if (j < 2)
//Output for invalid pin number
cout << endl << "Invalid pin";
cout << endl << "You have " << 2-j << " more tries" << endl << endl;
//add color to error message
//add color to error message
system ("Color 3a");
}
//If statement if pin number is wrong three times
if (!found)
{
//Display output of wrong pin three times
cout << endl << "Invalid pin";
cout << endl << "System aborting";
cout << endl << "Your account has been locked" << endl;
//Add a pause to the program
system("pause");
//add color to error message
//add color to error message
system ("Color 3a");
//Return a value
return -1;
}
}
Topic archived. No new replies allowed.