#include #include #include #include using namespace std; int main() { double principal {0.00}; double annual_rate {0.00}; int months {0}; cout << "Enter the loan amount: $\n"; cin >> principal; if (!cin) { cerr << "Sorry, input failed.\n"; return EXIT_FAILURE; } cout << "Enter the annual interest rate (e.g., 5.0 for 5%): \n"; cin >> annual_rate; if (!cin) { cerr << "Sorry, input failed.\n"; return EXIT_FAILURE; } cout << "Enter the loan term in months: \n"; cin >> months; if (!cin) { cerr << "Sorry, input failed.\n"; return EXIT_FAILURE; } const double monthly_rate {(annual_rate / 100) / 12}; double balance {principal}; const double monthly_payment {principal * (monthly_rate * pow(1 + monthly_rate, months)) / (pow(1 + monthly_rate, months) - 1)}; cout << "\nMonthly Payment: $" << fixed << setprecision(2) << monthly_payment << "\n"; cout << "Amortization Schedule:\n"; cout << "Month\tPrincipal Paid\tInterest Paid\tRemaining Balance\n"; for (int i = 1; i <= months; ++i) { const double interest_paid {balance * monthly_rate}; const double principal_paid {monthly_payment - interest_paid}; balance -= principal_paid; cout << i << "\t$" << principal_paid << "\t$" << interest_paid << "\t$" << balance << "\n"; } return EXIT_SUCCESS; }