I needed to create a mortgage calculator for an intro to CS class. As part of the assignment, with an interest rate of 6% needs to change to 7% after 3 years hence that if statement. The char dummy line at the end is a requirement from my professor.
I'm mainly looking for ways to clean it up or if I missed anything. I'm required to use namespace std, and I know a lot of you don't care for it.
#include <iostream> using namespace std; int main() { double monthlyPayment; double balance; double interestRate; double interestPaid; double initialBalance; double termOfLoan; double month = 1; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "Enter the current balance of your loan: $"; cin >> balance; cout << "Enter the initial yearly interest rate : "; cin >> interestRate; cout << "Enter the desired monthly payment : $"; cin >> monthlyPayment; initialBalance = balance; while (interestRate >= 1) /*Converts the interest rate to a decimal if the user inputs in percentage form*/ { interestRate = interestRate / 100; } if(month >= 36); { if(interestRate=.06) { interestRate=.07; } } balance = balance * (1 + interestRate / 12) - monthlyPayment; cout << "After month 1 your balance is $" << balance << endl; while (balance > 0) { if (balance < monthlyPayment) { balance = balance - balance; } else { balance = balance * (1 + interestRate / 12) - monthlyPayment; } month = month++; month = month + 1; month += 1; cout << "After month " << month << ", your balance is : $" << balance << endl; } cout << "You have paid off the loan at this point. Congratulations!" << endl; termOfLoan = month; interestPaid = (monthlyPayment * termOfLoan) - initialBalance; /*I believe the formula above would work if only there was a way to calculate how many months it took to pay off the loan, but since it varies, I don't know how to calculate "termOfLoan". */ cout << "You paid a total ammount of $" << interestPaid << " in intrest." << endl; cout << "Total number of months = " << month << "." << endl; char dummy; cout << "Enter any key to quit." << endl; cin >> dummy; }