This s the problem they gave me:
Write a function declaration for a function that computes
interest on a credit card account balance. The function takes
arguments for the initial balance, the monthly interest rate, and
the number of months for which interest must be paid. The value
returned is the interest due. Do not forget to compound the interest,
that is, to charge interest on the interest due. The interest due
is added into the balance due, and the interest for the next month
is computed using this larger balance. Use a while-loop that is
similar to (but need not be identical to) the one shown in Display
2.14 of the slides. Embed the function in a program that reads the
values for the interest rate, initial account balance, and number
of months, then outputs the interest due. Embed your function
definition in a program that lets the user compute interest due on
a credit account balance. The program should allow the user to
repeat the calculation until the user said he or she wants to end
the program.
this is how i tackled it, its been a while since i worked with compound interest, so I don't know/ remember if my code is right, was trying different online calculators but all gave me different inputs and different outputs... plz help....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
using namespace std;
double CompoundInterest(double balance,double month,double rate);
int main()
{
double month,rate,balance;
cout << "How much do you owe?: $";
cin >> balance;
cout << endl <<"What is your interest rate?(integer form [1-100]): %";
cin >> rate;
cout << endl <<"How many moths will you take to pay for it?: ";
cin >> month;
cout << endl << "This is what you will pay: $" << CompoundInterest(balance,month,rate);
return 0;
}
double CompoundInterest(double balance,double month,double rate)
{
for(int i = 0;i < month;i++)
{
double balanceDue,interestDue;
balanceDue = balance + (balance * rate/100);
interestDue = balanceDue - balance;
balance = balanceDue;
}
return balance;
}
|