0

I am writing a program and stuck on a part of my coding. This part of the instructions say the following...

11 - User can only withdrawl $300 amount per day

I guess my problem is I am not sure how to set this up where it is linked to a pin number as well as a specific date. If this sounds confusing let me know as I am having a hard time trying to explain it....Here is the code I have...

/*
Information of Program...
Programmed by: Bryan Kruep
Programmed by: Aaron Arsea
Programmed by: third member of team
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();

    //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;
        }
        
        //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: ";
    }

/*    
*********************************************************************
*********************************************************************
* 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
            {
                //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;

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

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

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

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

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

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

			//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();
        }

/*
**********************************************************
**********************************************************
* Enter amount screen                                    *
* Function to enter amount screen                        *
**********************************************************
**********************************************************
*/
double enterAmountScreen(double money)
{
    //Declare function variables
    int decision,
    anotherTransactionChoice = 0;
            
    //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;

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

    if (decision == 2)
    {
		//Return a value
        return -1;
    }

	//Perform else statement
    else
    {
		//Prompt user to enter the amount
        cout << "Please enter the amount: ";
        cin >> money;

		//Function to perform withdrawMax
		withdrawMax();

		//Perform anotherTransactionScreen function
		anotherTransactionScreen(anotherTransactionChoice);

		//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;
		
		/*
		********************************************************************
		********************************************************************
		* Check for validation                                             *
		* Use while statement                                              *
		********************************************************************
		********************************************************************
		*/

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

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

/*
*****************************************************************
*****************************************************************
* 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
	bool found;
	string valid;
	char pin[4];
    int pinChoice,
		i,
		j;
	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;

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

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

        //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
		for (i = 0; i < 4; i++)
		{
		//input the pin
		cin >> pin[i];
		}

    //Open the file
    Input.open("pin.txt");  
    
    //Perform error test
    if(Input.fail( ))
    {
        //Display error opening file.
        cout << endl << "Error opening input file" << endl;
    }

	//Determine if false
	found = false;

	//Input valid
	Input >> valid;

	//Perform while statement
	while (Input && !found)
	{
		//Perform for loop
		for (i = 0; i < 4; i++)
		{
			//if statement for pin
			 if (pin[i] != valid[i])
			i = 6;
		}

		//Determine if true with if statement
		if (i == 4)
			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;
}

	//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;
		system("pause");

		//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                                  *
*********************************************************
*/

void withdrawMax()
{
	//enter informaiton here
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by VernonDozier
0

That's a lot of code and your question only pertains to a very small portion of the code (or at least it will if the code is designed well). You're going to have to point us in the right direction and ask something far more specific.

Somewhere in there you should have a function that calculates the maximum amount someone can withdraw. I would imagine that would be something like:

maxWithdraw = min (acctBalance, dailyWithdrawMaximum - amountWithdrawnSoFarToday)

The customer will make a request to withdraw a certain amount. If that amount is greater than the amount above, the request should be rejected.

This should have nothing to do with the PIN. If the PIN is incorrect, you should not get this far.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.