# Thread: interest on negative balances

1. ## 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. 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. 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. 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.