Hello all! I'm new to the forum and need some help. I finished most of the code already but I am stuck now. I'm trying to create a program that shows the interst and payment on a loan. I want to add som code that will sum the amount of interest paid in total and allow you to pay extra on the principla of at any payment. Thanks in advance for any help.

``````#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
float prin, air = .1, np = 36, date, pay, mpr, mi, bal;
int n = 0, year = 13, month = 0;

cout<<"Enter principal amount: \n";
cout<<"\$";
cin>>bal;

cout<<"Enter annual interest rate in decimal form: "<<endl;
cin>>air;

cout<<"Enter number of payments in months: \n";
cin>>np;

mpr = air / 12;

pay = mpr * (bal / (1 - (1 / pow((1 + mpr), np))));// WHY YOU NO WORK!!!!!!!

cout<<"Payment is: "<<pay<<endl;
cout<<"Payment: Due Date  Number Payment  Principal  Interest  Balance "<<endl;

while (n < np)
{
n++;
month++;
if (month>12)
{
month = 1;
year++;
}
mi = bal * mpr;
prin = pay - mi;
bal = bal - prin;
cout.setf(ios::fixed);
cout<<setw(10)<<setprecision(2)<<month<<"/5/"<<year<<setw(7)<<n<<setw(11)<<pay<<"   "<<prin<<"     "<<mi<<"     "<<bal<<endl;
}
return 0;
}
``````
4
Contributors
7
Replies
38
Views
4 Years
Discussion Span
Last Post by kortneycoles

make sure #include <stdlib> and system("PAUSE") in the code to dispplay.am not gettin ur logic very well.can u explain further.

Sorry, I just realized that I didn't explain very well. I need to have a section that sums up how ever much interest you paid on the loan all together and a section that will allow you to pay an extra amount during a single month.

make sure #include <stdlib> and system("PAUSE") in the code to dispplay.

That's only necessary when you're running the program from an IDE that closes the window after main() returns. Not all of them do that, and it's often not worth the subtle yet hideous security risk of invoking the system() function.

You can create an array to store the interest then sum the elements of the array to get the total of monthly accured interest ... as for your other problem to allow them to pay extra i'm guessing you have to display the info for one month and then prompt them again on how much they would pay

You can create an array to store the interest then sum the elements of the array to get the total of monthly accured interest ... as for your other problem to allow them to pay extra i'm guessing you have to display the info for one month and then prompt them again on how much they would pay

How exactly would I do that? Sorry, I'm pretty new to programming.

actually i'm sorry you wouldn't need the array at all just create another variable TotalInterest for example then do TotalInterest += mi;

Oh thanks that worked!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.