You should try the compound operators
ex:
+= , -= , *= , /= , %=
instead of
Payment = Payment - InterestPaid;
you can do
Payment -= InterestPaid;
Also it seems a bit redundant to do Payment -= InterestPaid
Then balance -= Payment
Why cant you just do balance -= InterestPaid?
Also technically speaking 18% annual interest is different than 1.5% monthly.
Say we start at 1000.
Annual(18%) = 820
Monthly(1.5%) = 834.13196834087708627557095727539
Since it does 1.5% interest on the current value and not the initial value.
Also I don't see your function doing what you say it should.
What you are saying is each month it is not paid off you owe an additional 1.5% and you are paying off 50$ a month
So say for example you start at 1000 dollars
that would mean
Month one you pay 50 so you owe 950$ then it isn't paid off for the first month so you now owe 964.25
Month two you pay off 50$ you now owe 914.25$ interest is added
you now owe 927.96375
Month three you pay off 50$ you now owe 877.97$ then they charge you the interest you now owe 891.13955
repeat...
I have made some code if this is what you are trying to do for your assignment ( I could be very wrong )
Maybe look something like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
int main() {
double loan = 1000.0;
const double INTEREST = 0.015;
const int PAYMENT = 50;
int month = 0;
while( loan > 0 )
{
loan -= PAYMENT;
loan *= 1 + INTEREST;
++month;
}
std::cout << "It took " << month << " months to pay off the loan." << std::endl;
return 0;
}
|
It took 24 months to pay off the loan. |
You might want to make it so say they owe 999.9123 dollars or w.e
then it rounds up a penny so they would really owe 999.92$
Banks are after all greedy for their money. They cant get their half pennies so they want a full penny.
*fixed a small typo