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. Any help with this would be lifesaver....here is the code where I think the problem is is...

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;
    }
}   

I know this prolly wont help cuz there is so much information but here is the entire code of this helps...

/*
Information of Program...
Class: C++ 230
Date: 2/16/10
Assignment: final
This program is my final for C++ 230
This program will perform typical functions of a normal ATM machine
*/

//Begin coding the program
#include <iostream>
#include <iomanip>
#include <time.h>
#include <fstream>
#include <conio.h>
#include <string>

using namespace std;

//Function prototypes
void showMenu();
int mainMenuSelection(int);
void welcomeScreen();
double enterAmountScreen(double);
int anotherTransactionScreen(int);
void goodbyeScreen();
void wait(int);
int dataEntryScreen();
void timeStamp();
//void withdrawMax();

/*
******************************************************************
******************************************************************
** MAIN FUNCTION                                                 *
** int main function                                             *
******************************************************************
******************************************************************
*/

int main ()
{
    //Declare variables
    int choice;

    //Set the numeric output formatting
    cout << fixed << showpoint << setprecision(2);

    //Function for welcome screen
    welcomeScreen();

    //Give space for the function of date and time
    cout << endl << endl;

    //Prompt to show today's date
    cout << "Today's date is: " << endl;

    //Show date and time function
    timeStamp();

    //Enter some space
    cout << endl << endl;

    //Function to enter a pin number
    choice = dataEntryScreen();

    //if statement for choice
    if (choice == -1)

        //Return a value
        return 0;

    //Create a do\while loop
    do
    {
        //Display the menu and get the user's choice.
        showMenu();
        cin >> choice;

        //Validate the menu selection.
        while (choice < 1 || choice > 5)
        {
            //Prompt user to reenter a correct choice
            cout << "Please enter 1, 2, 3, 4, or 5: ";
            cin >> choice;

            //add color to error message
            //add color to error message
            system ("Color 3a");
        }

        //Function to choose in the main menu selection
        mainMenuSelection(choice);

    //End the while statement
    } while (choice != 5);

    //Function returns a value
    return 0;
}

/*
***********************************************************
***********************************************************
* Main Menu Function                                      *
* Function to show the main menu                          *
***********************************************************
***********************************************************
*/

void showMenu()
    {
        //Display the main menu screen
        cout << endl << "\t\tMain Menu Screen" << endl << endl;
        cout << "1) Withdrawal" << endl;
        cout << "2) Deposit" << endl;
        cout << "3) Check Balance" << endl;
        cout << "4) Funds Transfer" << endl;
        cout << "5) Exit ATM" << endl << endl;
        cout << "Please enter a selection: ";

        //add color to background of main menu screen
        //add color to text of main menu screen
        system ("Color 1a");
    }

/*    
*********************************************************************
*********************************************************************
* Main Menu Screen                                                  *
* Function to choose in the main menu screen                        *
*********************************************************************
*********************************************************************
*/

int mainMenuSelection(int choice)
    {
        //Declare variables in mainMenuSelection
        int withdrawChoice,
            depositChoice,
            checkBalanceChoice,
            fundsTransferChoice;
        double money = 0.0;

        //Respond to user's menu selection
        switch (choice)
        {
        //switch case 1
        case 1:

            //Perform do\while loop to check for correct validation
            do
            {
                //let customer know he\she cannot withdraw more than 300 per day
                cout << endl << "You may not withdraw more than $300 for this date:" << endl << endl;

                //function to enter date and time
                timeStamp();

                //give some spaces from main menu
                cout << endl;

                //Show output of function
                cout << endl << "\t\tWithdrawal Screen" << endl << endl;
                cout << "1) From Checking" << endl;
                cout << "2) From Savings" << endl;
                cout << "3) Quick Cash" << endl;
                cout << "4) Back to Main Menu" << endl;
                cout << "Please enter a selection: ";
                cin >> withdrawChoice;

                //add color to background of withdraw screen
                //add color to text of main menu screen
                system ("Color 6a");

                //While statement to check validation
                while (withdrawChoice < 1 || withdrawChoice > 4)
                {
                    //Prompt user to reenter a correct number
                    cout << "Please reenter 1, 2, 3, 4: ";
                    cin >> withdrawChoice;

                    //add color to error message
                    //add color to error message
                    system ("Color 3a");
                }

                //Perform if statement
                if (withdrawChoice != 4)
                {
                    do
                    {
                    //Declare variables
                    int val = enterAmountScreen(money);

                    while (money > 300)
                    {
                        cout << "An error has occurred!" << endl;
                        cout << "You have withdrawn more than the max allowed per day!" << endl;
                        cout << "Please enter a withdraw amount less than or equal to $300: ";
                        cin >> money;

                        //add color to error message
                        //add color to error message
                        system ("Color 3a");
                    }

                    cout << "You have withdrawn $" << money << endl;

                    } while (money > 300);

                    //Return the value
                    return -1;
                }

            //Complete do\while statement
            } while (withdrawChoice != 4);

            //Back to main menu option
            if (withdrawChoice == 4)
            {
                //Return a value
                return -1;
            }

            //Perform a break to go to next case
            break;

        //Perform case 2
        case 2:

            //Perform do\while loop to check for correct validation
            do
            {
                //Display output of Deposit Screen
                cout << endl << "\t\tDeposit Screen" << endl << endl;
                cout << "1) To Checking" << endl;
                cout << "2) To Savings" << endl;
                cout << "3) Back to Main Menu" << endl;
                cout << "Please enter a selection: ";
                cin >> depositChoice;

                //add color to background of withdraw screen
                //add color to text of main menu screen
                system ("Color 6b");

                //Check for validation
                while (depositChoice < 1 || depositChoice > 3)
                {
                    //Prompt user to enter a correct choice
                    cout << "Please reenter 1, 2, or 3: ";
                    cin >> depositChoice;

                    //add color to error message
                    //add color to error message
                    system ("Color 3a");
                }

                //Perform an if statment
                if (depositChoice !=3)
                {
                    //Declare value in function
                    int val = enterAmountScreen(money);

                    //Return a value
                    return -1;
                }

            //end do\while loop
            } while (depositChoice != 3);

            //Back to main menu option
            if (depositChoice == 3)
            {
                //Return a value
                return -1;
            }

            //Perform a break to go to next case
            break;

        //Prompt to enter case 3
        case 3:

            //Perform do\while loop to check for correct validation
            do
            {
                //Display output
                cout << "\t\tCheck Balance Screen" << endl << endl;
                cout << "1) From Checking" << endl;
                cout << "2) From Savings" << endl;
                cout << "3) Back to Main Menu" << endl;
                cout << "Enter enter a selection: ";
                cin >> checkBalanceChoice;

                //add color to background of withdraw screen
                //add color to text of main menu screen
                system ("Color 6c");

                //Check for validation
                while (checkBalanceChoice < 1 || checkBalanceChoice > 3)
                {
                    //Check for validation
                    cout << "Please reenter 1, 2, or 3: ";
                    cin >> checkBalanceChoice;

                    //add color to error message
                    //add color to error message
                    system ("Color 3a");
                }

            //End while statement
            } while (checkBalanceChoice != 3);

            //Back to main menu option
            if (checkBalanceChoice ==3)
            {
                //Return a value
                return -1;
            }

            //Perform break to go to next case
            break;

        //Prompt to begin case 4
        case 4:

            //Perform do\while loop to check for correct validation
            do
            {
                //Display output
                cout << "\t\tFunds Transfer Screen" << endl << endl;
                cout << "1) From Savings to Checking" << endl;
                cout << "2) From Checking to Savings" << endl;
                cout << "3) Back to Main Menu" << endl;
                cout << "Please enter a selection: ";
                cin >> fundsTransferChoice;

                //add color to background of withdraw screen
                //add color to text of main menu screen
                system ("Color 6d");

                //Check for validation
                while (fundsTransferChoice < 1 || fundsTransferChoice > 3)
                {
                    //Prompt user to enter correct selection
                    cout << "Please reenter 1, 2, or 3: ";
                    cin >> fundsTransferChoice;

                    //add color to error message
                    //add color to error message
                    system ("Color 3a");
                }

                //Perform if statement
                if (fundsTransferChoice != 3)
                {
                    //Declare values in function
                    int val = enterAmountScreen(money);

                    //Return a value
                    return -1;
                }

            //End do while loop
            } while (fundsTransferChoice != 3);

            //Back to main menu option
            if (choice == 3)
            {
                //Return a value
                return -1;
            }

            //Prompt to break to next case
            break;

        //Prompt to enter next case
        case 5:

            //End the program if 5 is selected
            cout << "Program ending." << endl << endl;

            //add color to background of withdraw screen
            //add color to text of main menu screen
            system ("Color 6e");

            //Perform break
            break;
        }

        //Returns a value
        return 0;
    }

/*
**********************************************************
**********************************************************
* Welcome Screen                                         *
* Function to display the welcome screen                 *
**********************************************************
**********************************************************
*/
void welcomeScreen()
        {
            //Show output of function
            cout << "Hit enter to simulate inserting card";
            //Hit enter to go to the next screen
            cin.get();

        //add color to background of main menu screen
        //add color to text of main menu screen
        system ("Color 1b");
        }

/*
**********************************************************
**********************************************************
* Enter amount screen                                    *
* Function to enter amount screen                        *
**********************************************************
**********************************************************
*/
double enterAmountScreen(double money)
{
    //Declare function variables
    int decision,
    anotherTransactionChoice = 0;

    //prompt user to begin do statemen
    do
    {
        //Show output of function
        cout << endl << "\t\tEnter Amount Screen" << endl;
        cout << "1) Enter an amount:";
        cout << endl << "2) Back to Main Menu:";
        cout << endl << "Please enter a selection: ";
        cin >> decision;

        //add color to background of enter amount screen
        //add color to text of enter amount screen
        system ("Color 1c");

        /*
        *******************************************
        * Return to main menu option              *
        * Create if statement for decision        *
        *******************************************
        */

        while (decision < 1 || decision > 2)
        {
            //Enter a correct number
            cout << "Please reenter 1 or 2: ";
            cin >> decision;

            //add color to error message
            //add color to error message
            system ("Color 3a");
        }

        if (decision == 2)
        {
            return -1;
        }

        //Perform next if statement
        if (decision == 1)
        {
            //Prompt user to enter the amount
            cout << "Please enter the amount: ";
            cin >> money;
        }

        } while (decision < 1 || decision > 2);


        //Perform anotherTransactionScreen function
        anotherTransactionScreen(anotherTransactionChoice);

        //Create a space
        cout << endl;

        //Perform timeStamp function
        timeStamp();


    //Return a value
    return money;


}

/*
***********************************************************************
***********************************************************************
* Another Transaction Screen                                          *
* Function to enter another transaction screen                        *
***********************************************************************
***********************************************************************
*/

int anotherTransactionScreen(int anotherTransactionChoice)
{
    //Perform a do statement
    do
    {
        //Display output
        cout << endl << "\t\tAnother Transaction Screen" << endl;
        cout << "1.) Enter another transaction" << endl;
        cout << "2.) Exit the ATM ";
        cout << endl << "Please enter a selection: ";
        cin >> anotherTransactionChoice;

        //add color to background of another transaction screen
        //add color to text of another transaction screen
        system ("Color 1d");

        /*
        ********************************************************************
        ********************************************************************
        * Check for validation                                             *
        * Use while statement                                              *
        ********************************************************************
        ********************************************************************
        */

        while (anotherTransactionChoice < 1 || anotherTransactionChoice > 2)
        {
            //Enter a correct number
            cout << "Please reenter 1 or 2: ";
            cin >> anotherTransactionChoice;

            //add color to error message
            //add color to error message
            system ("Color 3a");
        }

        //If statement to return to main menu
        if (anotherTransactionChoice == 1)
        {
            //Return a value
            return -1;
        }

        //If statement to display the goodbye screen and exit
        if (anotherTransactionChoice == 2)
        {
            //Go to goodbye function
            goodbyeScreen();

            //Return a value
            return 1;
        }

    //end do\while statement
    } while (anotherTransactionChoice == 2 || anotherTransactionChoice == 1);

    //Return a value
    return anotherTransactionChoice;
}

/*
***************************************************************
***************************************************************
* Goodbye Screen                                              *
* Function to display goodbye Screen                          *
***************************************************************
***************************************************************
*/

void goodbyeScreen()
{
    //Declare variables in goodbye screen
    int seconds = 10;

    //Display a goodbye message
    cout << endl << endl << "Have a nice day!" << endl << endl;
    wait(seconds);

    //add color to background of goodbye screen
    //add color to text of googbye screen
        system ("Color 1f");
}

/*
*****************************************************************
*****************************************************************
* Wait function                                                 *
* Function to wait 10 seconds before returning to main menu     *
*****************************************************************
*****************************************************************
*/

void wait(int seconds)
{
    //Declare variables
    clock_t endwait;

    //Calculate seconds
    endwait = clock () + seconds * CLK_TCK ;

    //Perform while statement for seconds
    while (clock() < endwait) {}
}


/*
***********************************************************
***********************************************************
* Enter pin                                               *
* Function to enter a pin number                          *
***********************************************************
***********************************************************
*/

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;
    }
}   

/*
********************************************************************
********************************************************************
* Enter timestamp                                                  *
* Function to enter timestamp                                      *
********************************************************************
********************************************************************
*/

void timeStamp()
{
    //Calendar time
     time_t ltime;

     //Get current cal time
     ltime=time(NULL);

     //Prints out the results
     printf("%s",asctime( localtime(&ltime) ) );
}

/*
*********************************************************
* Withdraw Max                                          *
* Function to place a limit on                          *
* drawing the max cash                                  *
*********************************************************
*/

//double withdrawMax(double money)
//{

//}

Edited 4 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.