# Help with a small equation and loop

• 09-30-2005
Zerohero11
Help with a small equation and loop
I need to calculate how much time it will take to pay off a credit card. I'll take any help.

Code:

```#include <iostream> using namespace std; int main() {         float bal,ir,payment,year, newbal,newbal2; cout << "Enter credit card Balance" << endl; cin >>bal; cout <<"Enter Intrest rate" << endl; cin >>ir; cout << "Enter years:" << endl; cin>> year; for( newbal =1 ; newbal <=12 ; newbal++) { // Formula payment = ((bal*ir)/year)+10; cout << " Payment each month:"<<  payment<< endl; newbal = bal + ir - payment; cout << newbal<<endl; newbal2 = (newbal-(payment*12)+ir); cout << newbal2<< endl; cout <<"total amount months to pay of debt " <<newbal2<< endl;         } system("pause");         return 0;```
• 09-30-2005
Salem
Think about what controls your loop, and what calculates a new balance

> for( newbal =1 ; newbal <=12 ; newbal++)
> newbal = bal + ir - payment;
These are inconsistent.
• 09-30-2005
Enahs
Well, for starters. Your math is wrong.

Code:

`newbal = bal + ir - payment;`
Will not calculate the new balance properly.

Interest rate is a %. 6% of 100 is different that 6% of 1000.

So, divide you interest rate by one hundred.
Then the interest acquired is the balance times that interest rate divided by 100.

example:

5.98765% interest of 123456 dollars.
5.98765 / 100 = 0.0598765
123456 + (123456 * 0.0598765) = 130848.11

Also, you can if you chose to do this:

Code:

` newbal2 = (newbal-(payment*12)+ir);`
Is fine, but you do NOT have to have a new variable every time you change something.
The following is just as valid:

Code:

` newbal = (newbal-(payment*12)+ir);`
There are perfectly legit reasons to use the method you are using, I am just letting you know this incase you do not know.

Ok, now onto your program.
Play with the math on some paper and pencil and calculator. There is a simpler way of doing this than the method you are trying.
• 10-03-2005
Zerohero11
Alright, well I figured I need to change the loop, and x the percent by 100 so far. Still working on everything else.