keeping count..

This is a discussion on keeping count.. within the C++ Programming forums, part of the General Programming Boards category; Hello again, I am having a hard time keeping the updated balances, can someone please help me? this is are ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    20

    keeping count..

    Hello again,

    I am having a hard time keeping the updated balances, can someone please help me?

    this is are my functions in a class called "functions"

    Code:
       void DepositAmt(double *dep_amount,double *cur_bal)
        {
            *dep_amount = *dep_amount + *cur_bal;
        }
    
        void WithdrawalAmt(double *wdl_amount,double *cur_bal)
        {
            *wdl_amount = *cur_bal - *wdl_amount;
        }
    
        void PrintStatement(Account acc)
        {
            acc.get_data();
        }
    
        void getFinalBalance(double *cur_bal, double *dep_amount, double *wdl_amount)
        {
            *cur_bal = *cur_bal + *dep_amount - (wdl_amount;
        }
    and here is my main snippet

    Code:
            if (choice == 1)
            {
                numtrans = numtrans + 1;
                cout<<"*************************************************"<<endl;
                cout<<"Please enter the amount you would like to deposit"<<endl;
                cin>>dep_amount;
                func.DepositAmt(&dep_amount, &cur_bal);
            }
    
    cout<<"you have deposited : "<<dep_amount<<endl;
        cout<<"you have withdrew : "<<wdl_amount<<endl;
        cout<<"your current balance is: "<<cur_bal<<endl;
    my problem is that in the end, when I want to display the total deposited and the current balance, it only displays the last amount that I deposited and current balance at zero.

    I have tried various things and your help would be appreciated.

    thank you in advance.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,738
    >> I am having a hard time keeping the updated balances, can someone please help me?

    Your math is wrong. The current balance (cur_bal) is what should be modified, not the other amounts.

    Since the point of a class is to model the data of your program, why isn't the balance amount a data member of the Account class? It would be easy to maintain the changes to all of the balances, if the balance were contained in the class in the first place.


    >> this is are my functions in a class called "functions"

    This undermines the design of your account class.
    Last edited by whiteflags; 06-26-2012 at 10:53 PM.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    20
    thank you very much for your response.

    the instructions of the assignment was to keep the information of the user in the header file within the Account class and all the deposit and withdrawal functions within the main in another class.

    that is why I am having a bit of a hard time with this assignment.

    This is all new stuff for me, so I am really racking my brain trying to learn.

    any other tips or advice would be greatly appreciated.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    whiteflags' response does not conflict with any of what you have been asked to do, and will in fact be precisely what is expected for your assignment.
    Please look up what it means for something to be a member of a class.

    You need to try to do as has been advised, and you may not get many further responses until you've shown your attempt at doing so, because that advice pretty much covers what you need to do.
    So, to be perfectly clear, we are now waiting on you.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Uppercase/Lowercase/Word COunt/Char count
    By Charak in forum C Programming
    Replies: 7
    Last Post: 02-23-2011, 07:16 AM
  2. Keeping pids
    By DarrenY in forum C Programming
    Replies: 6
    Last Post: 06-04-2006, 03:14 AM
  3. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM
  4. Replies: 2
    Last Post: 05-05-2002, 01:38 PM

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