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.
1. INTEREST, BALANCE and principal become negative.
2.what does it mean with"posible use of 'balance'
can anyone solve my coding.
double AnualInterestRate, monthlyInterestRate, loan_amount, monthlyPayment, total_payment, interest, principal, balance;
cout << "Loan Amount: ";
cin >> loan_amount;
cout << "Number of Years: " ;
cin >> num_year;
cout << "Annual Interest Rate: ";
cin >> AnualInterestRate;
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;