#include <iostream>
#include <cmath>
using namespace std;
// Function to compute loan amortization schedule
void computeAmortization(double principal, double annualRate, int numPayments) {
double monthlyRate = annualRate / 12.0 / 100.0;
double monthlyPayment = principal * (monthlyRate * pow(1 + monthlyRate, numPayments)) / (pow(1 + monthlyRate, numPayments) - 1);
cout << "Monthly Payment: $" << monthlyPayment << endl;
cout << "----------------------------------------------" << endl;
cout << "Payment\t|\tPrincipal\t|\tInterest\t|\tBalance" << endl;
double balance = principal;
for (int i = 1; i <= numPayments; ++i) {
double interest = balance * monthlyRate;
double principalPaid = monthlyPayment - interest;
balance -= principalPaid;
cout << i << "\t|\t$" << principalPaid << "\t|\t$" << interest << "\t|\t$" << balance << endl;
}
}
int main() {
// Sample loan details
double principal = 100000; // Principal amount
double annualRate = 5.0; // Annual interest rate (in percentage)
int numPayments = 12 * 30; // Number of monthly payments (e.g., 30 years)
// Compute loan amortization schedule
computeAmortization(principal, annualRate, numPayments);
return 0;
}