I just need to update the variables of the table each time z is less or equal to n. That is the only help I need ): because it's printing the same value and I know why but I don't know how to update these variables again. Thanks in advance.
The testing I use is
Loan = 10000
Interest = 12
Payments in months = 15
#include <iostream>
#include <cmath>
using namespace std;
int main() {
//Variables
float l, air;
int n, z = 1, count, mainInterest = 100;
double countingBalance, previousBalance, countingPrincipal, counterPrincipal, interestCounter, interestfinal = 6.50, mainPrincipal = 6.21;
//Inputs of the user
cout << "Enter loan amount: " << endl;
cin >> l;
cout << "Enter annual interest rate: " << endl;
cin >> air;
cout << "Enter number of payments in months: " << endl;
cin >> n;
//Calculation
float rate = air / 12.00;
rate = rate / 100;
float monthlyPayment = (rate * pow(1 + rate, n) *l) / (pow(1 + rate, n) -1);
float payment = monthlyPayment * n;
float interestPaid = payment - l;
double principal = monthlyPayment - 100;
double endingBalance = l - principal;
//Output
cout << "Monthly Payment: $" << monthlyPayment << endl;
cout << "Amount paid back: $" << payment << endl;
cout << "Interest paid: $" << interestPaid << endl;
cout << "\n----------------------------------Amortization Schedule----------------------------------------" << endl;
cout << "\tBeginning Balance" << "\tInterest" << "\tPrincipal" << "\tEnding Balance" << endl;
cout << z << "\t $" << l << "\t $100" << "\t $" << principal << "\t $" << endingBalance << endl;
//Updating the table - Variables to update the table
countingPrincipal = principal + mainPrincipal;
countingBalance = l - countingPrincipal;
interestCounter = mainInterest - interestfinal;
previousBalance = countingBalance - principal;
counterPrincipal = principal + mainPrincipal;
while (z <= n) {
count = z++;
cout << z << "\t $" << countingBalance << "\t $" << interestCounter << "\t $" << counterPrincipal << "\t $" << previousBalance << endl;
}
return 0;
}