Hi all, I'm new to C++ & taking my first class in programming.

The program ask the user to enter the loan amount, number of years, and interest rate, and then displays the amortization schedule for the loan.The monthly payment for a given loan pays the principal and the interest. The monthly interest is computed by multiplying the monthly interest rate and the balance (the remaining principal). The principal paid for the month is therefore the monthly payment minus the monthly interest.

I have a problem with cout of this program.

first :
1. INTEREST, BALANCE and principal become negative.
2.what does it mean with"posible use of 'balance'

can anyone solve my coding.

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


void main()
{
double AnualInterestRate, monthlyInterestRate, loan_amount, monthlyPayment, total_payment, interest, principal, balance;
int num_year;

cout << "Loan Amount: ";
cin >> loan_amount;

cout << "Number of Years: " ;
cin >> num_year;

cout << "Annual Interest Rate: ";
cin >> AnualInterestRate;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

monthlyInterestRate = AnualInterestRate / 12;

monthlyPayment = loan_amount * monthlyInterestRate / (1 - 1 / pow(1 + monthlyInterestRate, num_year * 12));

total_payment = monthlyPayment * (num_year * 12);


cout << "\nCalculation... " << endl;

cout << "\nMonthly Payment: " << monthlyPayment << endl;
cout << "Total Payment: " << total_payment << endl;

cout <<setw(0) << "\nPayment#" << setw(14) << "Interest" << setw(15) << "Principal" << setw(20) << "Balance" <<endl;

for (int i = 1; i <= num_year * 12; i++)
{
interest = monthlyInterestRate * balance;
principal = monthlyPayment - interest;
balance = balance - principal;

cout << setw(0)<< i << setw(20) << interest << setw(14) << principal << setw(20) << balance << endl;
}


getch();
}

>>void main()
It's int main() -- never void main

>>1. INTEREST, BALANCE and principal become negative
Its very rare that the amount of the final payment will be exactly the same as it was during the life of the loan. So you have to adjust the final payment so that the balance is 0.

The for loop needs to count one month less than num_year*12

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.