I have just completed a mortgage calculator for my intro to C++ programming class. The code compiles and meets all the instructors requirements. My future assignments will build on top of previous ones. So what I am asking for are opinions on how to write better code. My goal is to complete my assignments with fewest lines of code and still meet all the requirements. Any constructive criticism welcome.
#include <iostream>
#include <cmath> // must include for pow function
using std::cout;
using std::cin;
using std::endl;
int main ()
{
// defines varibles
double loanAmt = 0.0;
double interest = 0.0;
double term = 0.0;
char quit;
do
{
cout << endl;
cout << "Enter interest rate:";
cin >> interest;
cout << endl;
cout << "Enter term in years:";
cin >> term;
cout << endl;
cout << "Enter Loan amount:";
cin >> loanAmt;
cout << endl;
double monthlyPmt = loanAmt*(interest/1200)/(1-pow(1+(interest/1200),-1*term*12)); // amoritization formula
double monthlyInt = loanAmt * (interest/1200);
double principalPaid = monthlyPmt - monthlyInt;
double balance = loanAmt-monthlyPmt;
cout << "For a "<< loanAmt << " Loan your payment is " << monthlyPmt << endl;
cout << "\n";
cout << " New loan balance is " << balance << endl;
cout << "\n";
cout << " Your interest paid for this month is " << monthlyInt << endl;
cout << "\n";
cout << " Your Principal paid for this month is " << principalPaid << endl;
getchar(); // pauses the program and allows you to view the output
// user can continue in a loop or quit
//output
cout<<"\n";
cout<<"If you wish to continue press C then the enter key on your keyboard.\n";
cout<<"If you wish to quit press Q then the enter key on your keyboard.\n";
//user input
cin>>quit;
cout<<"\n";
while((quit!='q') && (quit!='Q') &&
(quit !='c') && (quit !='C'));
}
while((quit!='q') && (quit!='Q'));
cout<<"Thank you for trying my simple mortgage calculator\n";
}