Mortgage calculator for homework 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 &lt;iostream&gt;
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 &lt;&lt; "Enter the current balance of your loan: $";
    cin &gt;&gt; balance;
    cout &lt;&lt; "Enter the initial yearly interest rate : ";
    cin &gt;&gt; interestRate;
    cout &lt;&lt; "Enter the desired monthly payment : $";
    cin &gt;&gt; monthlyPayment;

    initialBalance = balance;

    while (interestRate &gt;= 1)       /*Converts the interest rate to a decimal if the user inputs 
                                                      in percentage form*/
    { 
        interestRate = interestRate / 100; 
    }

    if(month &gt;= 36);
    { 
        if(interestRate=.06)
        {
            interestRate=.07;
        }
    }
    balance = balance * (1 + interestRate / 12) - monthlyPayment;

    cout &lt;&lt; "After month 1 your balance is $" &lt;&lt; balance &lt;&lt; endl;

    while (balance &gt; 0)
    {
        if (balance &lt; monthlyPayment)
        {
            balance = balance - balance;
        }   
        else 
        {
            balance = balance * (1 + interestRate / 12) - monthlyPayment;
        }

        month = month++;
        month = month + 1;
        month += 1;     

        cout &lt;&lt; "After month " &lt;&lt; month &lt;&lt; ", your balance is : $" &lt;&lt; balance &lt;&lt; endl;
        }
        cout &lt;&lt; "You have paid off the loan at this point. Congratulations!" &lt;&lt; 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 &lt;&lt; "You paid a total ammount of $" &lt;&lt; interestPaid &lt;&lt; " in intrest." &lt;&lt; endl;
            cout &lt;&lt; "Total number of months = " &lt;&lt; month &lt;&lt; "." &lt;&lt; endl;

char dummy;
cout &lt;&lt; "Enter any key to quit." &lt;&lt; endl;
cin &gt;&gt; dummy;
}
You use double values for calculations. Especially for money, I would suggest to switch to int and handle it in cents. That way you can avoid problems with floating point precision.
You don't check if cin&gt;&gt; fails or succeeds. If the user doesn't enter a number you may have a problem here. A possible solution might be to let the user reenter the value as long as it isn't correct.

do
{
    cout &lt;&lt; "Enter the current balance of your loan: $";
}
while (!(cin &gt;&gt; balance));

You have a wrong check in the line if (interestRate = .06). You probably meant if (interestRate == .06). Additionally, this check might also be a problem as you do some calculations on interestRate that may cause inprecision (again floating point precision problem).

As you obviously await the user to input the value as int your check should be against 6 before you divide the value with 100.
You have this piece of code:

if (balance &lt; monthlyPayment)
{
    balance = balance - balance;
}


Which is the same as:

if (balance &lt; monthlyPayment)
{
    balance = 0;
}


I think the second version is easier to understand.


I didn't check any more of the code yet. I especially didn't prove it for correctness in you calculations.