C++ mortgage program problem

I have enclosed my code for a mortgage calculator which will let a user input the mortgage amount , rate, and term, this will calculate the mortgage and then display the principle with the interest in 2 lists which will continue until it reaches zero, but it has to stop ( I put 12 lines per display) and let the user decide if he/she wants to start a new mortage or quit or continue with the interest list.  I am stuck and I am not sure where i have gone wrong in my mind it should work :-)

here is the code:

//*******************************
//George L Reynolds Mortgage app- displays mortgage
//Week 4 assignment
//Allow users to enter input of mortgage rate, term, amount
//and also display the monthly interest and balance
//
//*******************************
#include <stdio.h>
#include <conio.h>
#include <ctype.h>  
#include <stdlib.h>
#include <cmath>
#include <iostream>
using namespace std;
int main()

{
double Mort_amt;
double rate;
int Mort_term;
float principal;
int NumberOfPayments;
int MonthlyPymt;
double LoanBalance;
double MonthlyIntPd;
double MonthlyPrinPd;
const char NL='\n';
const char TAB='\t';
char listmore;
int dividelist = 0;      
char quit;
 
do
{          
      //Get loan data
      cout << "Enter price of house: $";
      cin      >> Mort_amt;
      cout << "Enter term length of mortgage in months: ";
      cin  >> Mort_term;
      cout << "Enter the annual interest rate: ";
      cin  >> rate;

      //shows output
      cout << "\n week 3 mortgage assignment ";
      cout << "\n George L Reynolds ";
      cout << "\n ______________________________ ";
      cout << "\n\n Mortgage Amount: $"  << Mort_amt;  
      cout << "\n\n Term of loan in years  :  "  <<   Mort_term;    
      cout << "\n\n Interest Rate  :  "  <<   rate  << endl;      
     
      // monthly payment calc

      principal = Mort_amt * (rate/1200)/(1-pow(1+(rate/1200),-1*(Mort_term*12)));    

      cout<<endl<<Mort_term<<"yrs at "<<rate<<"%"<<endl;
     
      //output payment amount
      cout<<"\nYour Monthly Payment is $"<<principal<<".\n"<<endl;

      //loan balance and interest paid calculation    

      NumberOfPayments = Mort_term * 12;  //assign value to NumberOfPayments
      dividelist = 0;
     
      for (MonthlyPymt=1; MonthlyPymt<=NumberOfPayments; ++MonthlyPymt)
      {
      //Calculation for MonthlyIntPd to set up value for MonthlyPrinPd
      MonthlyIntPd = Mort_amt * (rate/1200);
      MonthlyPrinPd = principal - MonthlyIntPd;
      LoanBalance = Mort_amt - MonthlyPrinPd;
      if (LoanBalance < 0)
      LoanBalance = 0;
      Mort_amt = LoanBalance;   //end of payments
             
      //output loan balance and interest paid
      //only display heading once for every section
      if (dividelist == 0)
      {
      //cout<<"My Loan Balance and Interest Paid\n\n";
      cout<<"Loan Balance"<<TAB<<"Interest Paid"<<NL;
      cout<<"____________"<<TAB<<"_____________"<<NL<<NL;
      }
      cout<<LoanBalance<<TAB<<TAB<<MonthlyIntPd<<NL;
      ++dividelist;
             
      //check for user to continue
      if (dividelist==12)
     
      cout<<"Enter 'C' to continue,"<<"'N' for new data,"
      <<"'Q' to quit>";
      cin>>listmore;
      if ((listmore=='C')||(listmore=='c'))
      dividelist=0;
      else if ((listmore=='N')||(listmore=='n'))
      break;
      else if ((listmore=='Q')||(listmore=='q'))
      return listmore;
      return 0;
      }                  
   
    while ((quit!='q')&&(quit!='Q')&&(quit!='c')&&(quit!='C'));  // check user input
      cout<<"Enter C to continue, Q to quit>";
      cin>>quit;       //retrieve user input    
         
   return 0;
}
lescott68Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DanRollinsCommented:
#include <stdio.h>
#include <conio.h>
#include <ctype.h>  
#include <stdlib.h>
#include <cmath>
#include <iostream>
using namespace std;

int main()
{
      double Mort_amt;
      double rate;
      int Mort_term;
      float principal;
      int NumberOfPayments;
      int MonthlyPymt;
      double LoanBalance;
      double MonthlyIntPd;
      double MonthlyPrinPd;
      const char NL='\n';
      const char TAB='\t';
      char listmore;
      int dividelist = 0;      
      char quit;
 
      do {          
            //Get loan data
            cout << "Enter price of house: $";
            cin      >> Mort_amt;
            cout << "Enter term length of mortgage in months: ";
            cin  >> Mort_term;
            cout << "Enter the annual interest rate: ";
            cin  >> rate;

            //shows output
            cout << "\n week 3 mortgage assignment ";
            cout << "\n George L Reynolds ";
            cout << "\n ______________________________ ";
            cout << "\n\n Mortgage Amount: $"  << Mort_amt;  
            cout << "\n\n Term of loan in years  :  "  <<   Mort_term;    
            cout << "\n\n Interest Rate  :  "  <<   rate  << endl;      

            // monthly payment calc
            principal = Mort_amt * (rate/1200)/(1-pow(1+(rate/1200),-1*(Mort_term*12)));    

            cout<<endl<<Mort_term<<"yrs at "<<rate<<"%"<<endl;

            //output payment amount
            cout<<"\nYour Monthly Payment is $"<<principal<<".\n"<<endl;

            //loan balance and interest paid calculation    

            NumberOfPayments = Mort_term * 12;  //assign value to NumberOfPayments
            dividelist = 0;
     
            for (MonthlyPymt=1; MonthlyPymt<=NumberOfPayments; ++MonthlyPymt)
            {
                  //Calculation for MonthlyIntPd to set up value for MonthlyPrinPd
                  MonthlyIntPd = Mort_amt * (rate/1200);
                  MonthlyPrinPd = principal - MonthlyIntPd;
                  LoanBalance = Mort_amt - MonthlyPrinPd;
                  if (LoanBalance < 0) {
                        LoanBalance = 0;
                  }
                  Mort_amt = LoanBalance;   //end of payments

                  //output loan balance and interest paid
                  //only display heading once for every section
                  if (dividelist == 0)
                  {
                        //cout<<"My Loan Balance and Interest Paid\n\n";
                        cout<<"Loan Balance"<<TAB<<"Interest Paid"<<NL;
                        cout<<"____________"<<TAB<<"_____________"<<NL<<NL;
                  }
                  cout<<LoanBalance<<TAB<<TAB<<MonthlyIntPd<<NL;
                  ++dividelist;

                  //check for user to continue
                  if (dividelist==12) {
                        cout<<"Enter 'C' to continue,"<<"'N' for new data, 'Q' to quit";
                        cin>>listmore;
                        if ((listmore=='C')||(listmore=='c')) {
                              dividelist=0;  // restart the 12-unit list counter
                        }
                        else if ((listmore=='N')||(listmore=='n')) {
                              break;
                        }
                        else if ((listmore=='Q')||(listmore=='q')) {
                              return 0;
                        }
                  }
            }
            cout<<"Enter C to continue, Q to quit>";
            cin>>quit;       //retrieve user input    
      } while ((quit!='q')&&(quit!='Q')&&(quit!='c')&&(quit!='C'));
             
      return 0;
}
0
DanRollinsCommented:
Your main problem (and one you need to learn to avoid *right away*) is improper indenting.  That is why thje professor is such a jerk about it (I'm just guessing, but it's alwyas that way).

When you can't see *immediately* *at first glance* and without question where a do/while, if/else, of for loop ends, then it it really tough to see why the loops are malfunctioning.

In my book, proper style is to *always* use currly brackets, even for one-line if statements.

=--=-==--=
BTW, there is one other thing to fix... the program asks for duration of loan in MONTHS, but I think the program assumes YEARS.  Also, after the last payment, add another cout to let the user know that the last month has been output.  Also, for (completeness) each of those lines should have a payment number:

Pmt#  Loan Balance     Interest Paid
____  _____________   _____________
      1  61340.4             262.355
      2  59708.9             255.585
      3  58070.6             248.787
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lescott68Author Commented:
Thanks you Dan all your comments are right on and will do as you have suggested with the indenting and curly brackets.  I noticed as you pointed out I was thinking in years but coded for months in the term, arrrggghhhhh :-), thanks mate!
0
JIEXACommented:
How can you pay 262.355 ?
I mean that you calculations should give results in integers, in smallest currency part (cents for US).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.