I really need help with my ATM program

This is a discussion on I really need help with my ATM program within the C++ Programming forums, part of the General Programming Boards category; Hi Everyone, I have been working on this program for almost two weeks now and can not seem to progress ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    11

    Unhappy I really need help with my ATM program

    Hi Everyone,
    I have been working on this program for almost two weeks now and can not seem to progress any more. There are several problems that are blocking further progress for me. First, the program is an ATM that accepts one client account. I am using a class called ATM and it has three functions that withdrawal money, deposit money, and transfer money from one account to another. There are two accounts a checking and a savings. There are three private functions that print a receipt, print an error message that the withdrawal exceeds the balance, and another error message that says the daily withdrawal limit has been succeeded. I was messing around with this program so much that I am completely confused on how to fix it. Please can someone help me figure out how to fix it? Please I have tried and am getting nowhere.

    first problem: I realized that the savings balance which is suppose to be initialized to 200 by the MyAcct instance is not working.

    NOTE: I do not want someone to tell me the code to fix it. I want someone to help me figure out what is wrong so I can know what I did wrong and fix it.

    Here is the code and it is a lot.
    Code:
    //Preprocessor Directives
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    //ATM Class Declaration 
    class ATM 
    	{
    		//Private Data Member
    	private:
    		int saveBal;
    		int checkBal;
    		int curWithAmt;
    		
    		//Private Utility functions
    		void printRe(string ptrans, string pacct, int pmoney);
    		void printErr1();
    		void printErr2();
    		
    		//Public Member Functions
    	public:
    		ATM(int psaveBal, int pcheckBal);	//Overloaded Constructor
    		void deposit(string ptrans, string pacct, int pmoney);
    		void withdrawal(string ptrans, string pacct, int pmoney);
    		void transferTo(string ptrans, string pacct, int pmoney);
    	};
    
    //Implementation
    //ATM Constructor
    ATM::ATM(int psaveBal, int pcheckBal)
    {
    	while(psaveBal > 0 && pcheckBal > 0)
    	{
    		saveBal = psaveBal;
    		checkBal = pcheckBal; 
    	}
    	if(psaveBal <= 0)
    		saveBal = 0;
    	if(pcheckBal <= 0)
    		checkBal = 0;
    	
    	curWithAmt = 0;
    }//end constructor
    
    
    //Deposit function definition
    void ATM::deposit(string ptrans, string pacct, int pmoney)
    {
    	
    		if(pacct == "Checking Account")
    			checkBal = checkBal + pmoney;
    		
    		else if(pacct == "Savings Account")
    			saveBal = saveBal + pmoney;
    		
    		printRe(ptrans, pacct, pmoney);
    		
    }//end deposit function
    
    
    //Withdrawal function definition
    void ATM::withdrawal(string ptrans, string pacct, int pmoney)
    {
    	//local Variable for daily withrawal amount limit
    	int limit = 500;
    	
    	if(curWithAmt < limit)
    	{
    		if(pacct == "Checking Account" && pmoney <= limit && pmoney <= checkBal)
    		{
    			cout << "Here you are" << endl;
    			checkBal = checkBal - pmoney;
    			curWithAmt = curWithAmt + pmoney;
    			printRe(ptrans, pacct, pmoney);
    		}
    	
    		if(pacct == "Savings Account" && pmoney <= limit && pmoney <= saveBal)
    		{
    			saveBal = saveBal - pmoney;
    			curWithAmt = curWithAmt + pmoney;
    			printRe(ptrans, pacct, pmoney);
    		}
    	}
    		
    	if(pmoney >= saveBal || pmoney >= checkBal)
    	{
    		void printErr1();
    		return;
    	}
    		
    	if(pmoney + curWithAmt > curWithAmt)
    	{
    		void printErr2();
    		return;
    	}
    	return; 
    }//End set withdrawal function
    
    //Transfer to function call
    void ATM::transferTo(string ptrans, string pacct, int pmoney)
    {
    //	cout << "Please enter transfer amount: " << endl;
    //	cin >> pmoney;
    	
    	if(pacct == "Savings Account" && pmoney + saveBal <= saveBal)
    	{
    		checkBal = checkBal + pmoney;
    		saveBal = saveBal - pmoney;
    		void printRe(string ptrans, string pacct, int pmoney);
    
    	}
    
    	if(pacct == "Checking Account" && pmoney + checkBal <= checkBal)
    	{
    		saveBal = saveBal + pmoney;
    		checkBal = checkBal - pmoney;
    		void printRe(string ptrans, string pacct, int pmoney);
    	}
    	if(saveBal - pmoney > saveBal && pacct == "Savings Account")
    	{
    		void printErr1();
    		return;
    	}
    	if(checkBal - pmoney > checkBal && pacct == "Checking Account")
    	{
    		void printErr1();
    		return;
    	}
    }//end transfer to function
    
    //Print Receipt Function Definition
    void ATM::printRe(string ptrans, string pacct, int pmoney)
    {
    	cout << left;
    	cout << "---------------------------------------" << endl;
    	if(pacct == "Savings Account")
    	{
    		cout << setw(25) << "Transaction Type: " << ptrans << endl;
    		cout << setw(25) << "Account: " << pacct << endl;
    		cout << setw(25) << "Amount: " << "$" << pmoney << endl;
    		cout << setw(25) << "New Balance: " << "$" << saveBal << endl;
    	}
    	if(pacct == "Checking Account")
    	{
    		cout << setw(25) << "Transaction Type: " << ptrans << endl;
    		cout << setw(25) << "Account: " << pacct << endl;
    		cout << setw(25) << "Amount: " << "$" << pmoney << endl;
    		cout << setw(25) << "New Balance: " << "$" << checkBal << endl;
    	}
    	cout << "---------------------------------------" << endl;
    	
    }//End print receipt Function
    
    //Print Error 1 Function Definition
    void ATM::printErr1()
    {
    	cout << "Sorry balance has been exceeded." << endl;
    }//End print error 1 Function
    
    //Print Error 2 Function Definition
    void ATM::printErr2()
    {
    	cout << "Sorry daily withdrawal amount has been exceeded." << endl;
    }//End print error 2 Function
    
    
    //Client Program
    //Main Function
    int main () 
    {	
    	//Function Prototyes 
    	string inputTrans(); 
    	string inputAcct();
    	int inputMoney();
    	
    	//Variables
    	string trans;
    	string acct;
    	int money;
    	
    	ATM MyAcct(200, -200);	//Declaration of the only class object called MyAcct that will
    							//process ATM transactions.
    	cout << endl;
    	cout << "Welcome to the CS2020 ATM" << endl;
    //	cout << "-----------------------------" << endl;
    	
    	//write the statement that will call the inputTransaction functions and assign the account type
    	//and the money value.
    	trans = inputTrans();
    	
    	while(trans != "Quite")
    	{
    		//write the two statements that will call the function and assign
    		//the account type and the money value.
    		acct = inputAcct();
    		money = inputMoney();
    		
    		if(trans == "Deposit")
    			//Calls on the class's Deposit function using the class object.
    			MyAcct.deposit(trans, acct, money);
    		
    		else if(trans == "Withdrawal")
    			//Calls on the class's Withdrawal function using the class object.
    			MyAcct.withdrawal(trans, acct, money);
    		
    		else if(trans == "Transfer")
    			//Calls on the class's Transfer function using the class object.
    			MyAcct.transferTo(trans, acct, money);
    		
    		
    		//Write the statemnt that will call the function InputTransaction and assign
    		//the return value to transaction.
    		trans = inputTrans();		
    		
    	}
    	return 0; 
    }
    
    
    //----------------------------------------------------------------
    string inputTrans()
    {	
    	string trans;
    	
    	cout << "----------------------------------------\n";
    	cout << "(D)  Deposit\n"
    	<< "(W)  Withdrawal\n"
    	<< "(T)  Transfer To\n"
    	<< "(Q)  Quit\n";
    	cout << "----------------------------------------\n"
    	<< "Make a selection : ";
    	cin >> trans;
    	cout << trans << endl;
    	trans = toupper(trans[0]);						//Makes it so lower and upper case are accepted 
    	while (trans != "D" && trans != "W" && trans !=  "T" && trans != "Q")  // ADD YOUR CONDITION HERE
    	{	cout <<"Invalid selection, please try again.\n"
    		<< "Make a selection : ";
    		cin >> trans;
    		cout << trans << endl;
    		trans = toupper(trans[0]);					//Makes it so lower and upper case are accepted 
    	}
    	cout << "----------------------------------------\n";
    	// replace the letter with the actual word
    	// ADD YOUR CODE HERE
    	if(trans == "D")
    		trans = "Deposit";
    
    	else if(trans == "W")
    		trans = "Withdrawal";
    	
    	else if(trans == "T")
    		trans = "Transfer";
    	
    	else if(trans == "Q")
    		trans = "Quit";
    	
    	//end my added code
    	
    	return trans;
    }//end inputTrans Function
    //----------------------------------------------------------------
    
    string inputAcct()
    {	
    	string acct;
    	
    	cout << "----------------------------------------\n";
    	cout << "(C) Checking Account\n"
    	<< "(S) Savings Account\n";
    	cout << "----------------------------------------\n"
    	<< "Make a selection : ";
    	cin >> acct;
    	cout << acct << endl;
    	acct = toupper(acct[0]);						//Makes it so lower and upper case are accepted
    	while (acct != "C" && acct != "S") // ADD YOUR CONDITION HERE
    	{	cout <<"Invalid selection, please try again.\n"
    		<< "Make a selection : ";
    		cin >> acct;
    		cout << acct << endl;
    		acct = toupper(acct[0]);					//Makes it so lower and upper case are accepted
    	}
    	cout << "----------------------------------------\n";
    	// replace the letter with the actual word
    	//ADD YOUR CODE HERE
    	if(acct == "C")
    		acct = "Checking Account";
    	
    	else if(acct == "S")
    		acct = "Savings Account";
    	
    	//end my added code
    	
        return acct;
    }
    //----------------------------------------------------------------
    int inputMoney()
    {   int mon;
        cout << "Please enter the amount of money (multiple of 10s) : ";
        cin >> mon;
        cout << mon << endl;
        while (mon %10 != 0 || mon < 0) // ADD YOUR CONDIDTION HERE
        {   
    		cout << "The amount must be non-negative "
    			 << "and a multiple of 10.\n"
    			 << "Please try again : \n";
            cout << "Please enter the amount of money (multiple of 10s) : ";
    		
            cin >> mon;
            cout << mon << endl;
        }
    	return mon;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    while(psaveBal > 0 && pcheckBal > 0)
    	{
    		saveBal = psaveBal;
    		checkBal = pcheckBal; 
    	}
    What do you think that does?

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    11
    it is suppose to be an if, but it does not work either way. Suppose to set the saveBal or checkBal if the psaveBal or pchackBal is greater than 0. I should use if instead of while and or instead of and.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by ash4741 View Post
    it is suppose to be an if, but it does not work either way. Suppose to set the saveBal or checkBal if the psaveBal or pchackBal is greater than 0. I should use if instead of while and or instead of and.
    If the intent of the code is to initialize your variables, it should be nothing of the sort.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    11
    I changed it... now it works.

    if(psaveBal > 0)
    saveBal = psaveBal;
    else
    saveBal = 0;

    if(pcheckBal > 0)
    checkBal = pcheckBal;
    else
    checkBal = 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. c++ program for ATM machine
    By cplus2x in forum C++ Programming
    Replies: 2
    Last Post: 02-06-2008, 03:35 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21