Academic Project · C++
Loan Repayment Calculator
Console app that takes a principal, term, and interest rate — then spits out a full monthly schedule, classifies the loan type, and totals up everything you'll actually pay.
C++
Console App
Math Logic
Loops & I/O
What It Does
Takes principal, term & interest rate as input
Generates a full monthly repayment schedule
Classifies loan as Micro, Standard or Premium
Calculates total interest & service fee
Bugs Found & Fixed
FIXED
No input validation — entering 0 months or a negative rate would cause a division by zero or infinite loop. Added guard checks before the loop.
FIXED
Remaining balance goes negative — floating point rounding on the last month caused
rb to show e.g. -0.000003. Fixed by clamping the final balance to 0.
FIXED
No decimal formatting — output printed raw doubles like
1234.5 instead of 1234.50. Added fixed << setprecision(2) to all money outputs.
NOTE
Simple interest model — the formula uses flat principal/months for each payment rather than the standard amortization formula. Correct for the assignment scope, but worth knowing if you extend it.
Source Code
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
double pa, air, mir, pp, rb, tip, tm, ip;
string lt;
int sf;
tip = 0.0;
cout << "Enter principal loan amount: ";
cin >> pa;
cout << "Enter your total Number of Monthly Payments: ";
cin >> tm;
cout << "Enter your annual interest rate: ";
cin >> air;
// BUG FIX: validate inputs before doing any math
if (pa <= 0 || tm <= 0 || air < 0) {
cout << "Error: please enter valid positive values.\n";
return 1;
}
// BUG FIX: use fixed precision for all money output
cout << fixed << setprecision(2);
mir = (air / 100) / 12;
pp = pa / tm;
rb = pa;
cout << "_____Repayment Schedule_____" << endl;
cout << setw(8) << left << "Month"
<< setw(15) << right << "Interest"
<< setw(15) << right << "Principal"
<< setw(15) << right << "Total"
<< setw(15) << right << "Remaining" << endl;
for (int m = 1; m <= tm; m++)
{
ip = rb * mir;
double tmp = pp + ip;
rb = rb - pp;
tip = tip + ip;
// BUG FIX: clamp last-month rounding error to zero
if (rb < 0.001 && rb > -0.001) rb = 0.0;
cout << setw(8) << left << m
<< setw(15) << right << ip
<< setw(15) << right << pp
<< setw(15) << right << tmp
<< setw(15) << right << rb << endl;
}
cout << "\n_____Final Loan Summary_____" << endl;
if (pa < 50000)
{
lt = "Micro Loan";
sf = 100;
}
else if (pa <= 1000000)
{
lt = "Standard Loan";
sf = 500;
}
else
{
lt = "Premium Loan";
sf = 1000;
}
double tamountp = pa + tip + sf;
cout << "Loan Classification: " << lt << endl;
cout << "Mandatory Service Fee: RS " << sf << endl;
cout << "Total Interest Paid: RS " << tip << endl;
cout << "Total Amount Needed to Settle: RS " << tamountp << endl;
}