Thread: interest on negative balances

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    14

    Question interest on negative balances

    The last function that I need to write for my Uni assignment is to calculate compound interest. I have done this successfully for balances in credit but I am unsure what to so about balances in debit.

    This is a code excerpt
    Code:
    cout <<"\n\tHow many months to you wish to calculate the interest over? ";
    					cin >> months;
    					double principle = 1000;
    					amount = principal * pow( 1.0 + rate, months );
    					cout <<"\n\tAfter " << months <<" months with a principle of " << principle 
    						 <<"\n\tYour balance will be:"<< setiosflags( ios::fixed | ios::showpoint )<<"\t"
    						 << setprecision( 2 ) << amount <<"\n\n" << endl;
    This works, do I need to make it pow(-1-rate, months) for negative balances?

    Any help would be appreciated.

    ceevee

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    As far as I know interest is not given on neg balances. A fee might be imposed when you go negative. So a simple check to see if the principle is negative and skipping the interest amount should be enough

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    14
    What I mean is overdraft charges so they are in effect the opposite. I think that I have it figured out now.

    You need 3 algorithms I think.

    The one shown in the code.

    and two for negative balances, one if the power is a even number which is merely pow(-1-rate, months) and one that flips the minus sign if the power is an odd number.

    ceevee

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    wel if its the same formula:
    If the principle is negative, set a flag to remember that its negative, make the principle positive, if flag is set make negative.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-11-2009, 12:54 PM
  2. Programming project help?
    By Debbie Bremer in forum C++ Programming
    Replies: 21
    Last Post: 10-11-2008, 02:48 AM
  3. Compound Interest Formula
    By veronicak5678 in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2007, 05:16 PM
  4. compound interest
    By bliznags in forum C Programming
    Replies: 11
    Last Post: 03-20-2005, 01:46 AM
  5. how to handle integer overflow in C
    By kate1234 in forum C Programming
    Replies: 8
    Last Post: 04-23-2003, 12:20 PM