-
im just having so much confusion trying to figure out the right math to compute the interest. I know Im trying to calculate interest of each month...but the math statements throw me off. all i fized was the for loop. Other than that....im confused as to how i do the math calculations
this is what i fixed:
Code:
#include <iostream>
using namespace std;
int main ( )
{
int months, count = 1;
double init_Balance, rate, interest = 0, new_balance, total_Interest = 0, int_Accumulated;
char repeats;
do
{
total_Interest = 0;
{
cout << " Credit card interest\n ";
cout << "Enter: Initial balance, monthly interest rate as a decimal fraction, e.g. for 1.5% per month write 0.015, and the number of months the bill has run.\n ";
cout << "I will give you the interest that has accumulated.\n ";
cin >> init_Balance >> rate >> months;
}
for ( int count = 0; count < months; count++)
{
interest = ( rate * init_Balance );
new_balance = ( init_Balance + interest );
total_Interest = ( interest + );
cout << count ++;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
{
cout << "Interest accumulated = $\n";
cin >> int_Accumulated;
cout << "Y or y repeats, any other character quits. ";
}
}while ( repeats != 'Y' && repeats != 'y' );
return 0;
}
-
I fixed the first correction you told me to do...but im completely lost as to how i write the math statements in order to compute the interest for each month. How do i do that?
-
There are formulas for compounding interest that one could use that do not require a for loop in order to work properly...
I am not even going to torment my poor compiler with code that already looks uncompileable.
-
Being no economist I had to look up the formula for non-continuous interest... so let me put some code, Debbie. And see if mine helps you at any capacity.
Example:
Code:
#include <cmath>
/*
* A = P(1 + (r/n))^nt
*/
double compoundInterest(double principal, double rate,
double rate, double numberOfCompounds, double time)
{
return principal * pow(1.0 + (rate / numberOfCompounds), time * numberOfCompounds);
}
/*
* A = Pe^rt
*/
double continuousCompoundInterest(double principal, double rate, double time)
{
return principal * pow(M_E, rate * time);
}
-
Do I need to write my math statements in a series inside the for loop? Or would I use 1 statement like...interest = (init_Balance * pow (( 1 + rate/100 , months ))) - init_Balance;
I have no clue what to do? Can anyone help me? This is so frustrating?
-
-
Just a tip: but when you post your code, always make sure it's indented. This should not be a problem, since your original code should also be indented properly.
Otherwise it becomes an unreadable mess.