Can anyone help me - The screen never pauses or stays put (after the end while) for the last 3 lines of code to display and the line right above the end while -totalinterestpd is not being written to the outfile
I'm stumped.

while (MonthlyPayment <= LoanAmt)
    {
     MonthlyInterest = (ConvertedRate/NoOfMonths) * LoanAmt;
     TotalInterestPd += MonthlyInterest;
     LoanAmt = LoanAmt - (MonthlyPayment - MonthlyInterest);

     outfile << setfill(' ') << right << setw(15)
        << "Interest Amount" << setw(20) << "Loan Balance" << endl;
     outfile << setw(15) << MonthlyInterest << setw(20) 
          <<  LoanAmt << endl;
     outfile << setfill(' ') << left << setw(10) 
     <<  "Total interest paid: $ " << TotalInterestPd << endl;

    }    //end while

    cout << "Last payment Amount less than Loan Amt $ " <<  LoanAmt << endl;
    cout << "Last Payment amount is: $ " << LoanAmt << endl;
    cout << "Total amount of interest paid: $ " << TotalInterestPd << endl;
	

//	system ("pause");
    return 0;
}

Recommended Answers

All 5 Replies

Add cin.get() just before the return.

Thank you for your response. It now prints the Total Interest, it shows it as a running total. My aim is have the pgm show on the screen the last payment amount and the total interest pd over the loan. In the file all I need is the total interest that was pd. I don't know if it helps but I'm including the full code for the pgm.

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

	const double  ADDNTLPAYMENT = 5.0;

int main()
{
        //Declare and initialize variables         
    double LoanAmt = 0 ;
    double InterestRate = 0;
    int NoOfMonths = 0;
	int MonthlyPayment = 0;

    	  //Declare output variables 
    double MinimumPayment;
    double MonthlyInterest;  
    double TotalInterestPd = 0;
	double ConvertedRate;
//	double LastPayment;

    ofstream outfile;
    outfile.open("Ch5_Ex18_Output");                  

    outfile << fixed << showpoint;                  
    outfile << setprecision(2);                    
    cout <<fixed << showpoint;
	cout << setprecision(2);

	cout << "Loan Amount: $ ";
	cin >>	LoanAmt; 
	cout <<	endl;
	cout << "Length of Loan in months: "; 
	cin >> NoOfMonths;
	cout << endl;
	cout << "Interest on loan: ";
	cin >> InterestRate; 
		ConvertedRate = InterestRate/100;
		cout << endl;
		MinimumPayment = (ConvertedRate/NoOfMonths) * LoanAmt + ADDNTLPAYMENT;
		cout << "Minimum Payment Amount: $ " << MinimumPayment << endl;
		cout << "Payment Amount: $ "; 
		cin	>> MonthlyPayment;
		cout << endl;
		outfile << "Loan Amount: $ " << LoanAmt << endl;
		outfile << "Interest Rate: $ " << InterestRate << endl;
		outfile << "Length of Loan: " << NoOfMonths << endl;
		outfile << "Minimum Payment Amount: $ "<< MinimumPayment << endl;
		cout << endl;
		outfile << "Monthly Payment: $ "<< MonthlyPayment << endl;

   while (MonthlyPayment <= LoanAmt)
    {
	 MonthlyInterest = (ConvertedRate/NoOfMonths) * LoanAmt;
	 TotalInterestPd += MonthlyInterest;
	 LoanAmt = LoanAmt - (MonthlyPayment - MonthlyInterest);


	 outfile << setfill(' ') << right << setw(15)
			<< "Interest Amount" << setw(20) << "Loan Balance" << endl;
	 outfile << setw(15) << MonthlyInterest << setw(20) << LoanAmt << endl;
	 outfile << setfill(' ') << left << setw(10) 
		 << "Total interest paid: $ " << TotalInterestPd << endl;

    }    //end while

	cout << "Last payment Amount less than Loan Amt  $ " << LoanAmt << endl;
	cout << "Last Payment amount is: $ " << LoanAmt << endl;
	cout << "Total amount of interest paid: $ " << TotalInterestPd << endl;
	
	system ("pause");

    return 0;
}

Thank you for your response. It now prints the Total Interest, it shows it as a running total. My aim is have the pgm show on the screen the last payment amount and the total interest pd over the loan. In the file all I need is the total interest that was pd. I don't know if it helps but I'm including the full code for the pgm.

Where did you calculate the last payment and total interest? What variables did you use for them? Just output them.

I don't think I'm doing the calculations correctly. The assignment is to write a pgm that accpts as input - loan amount, interest rate, number of months. Then you are to figure what the minimum payment should be display that and then prompt them for what they want the monthly payment to be. If the payment they put in is less than the interest amount you tell them its to low. they also want the # of months to repay the loan,(I totally missed this in the assignment). When the min payment is more than the loan balance your supposed to let them know what the loan amount is before the last payment and give them the last payment amount and total interest paid on the loan. The teacher would like to have a output file like an amorization table with total interest pd.
I have most of it in the pgrm but I don't think my calculations are correct and I have no idea to to calculate # of months to pay off. We aren't as far as the pow stmt(not sure I understand that one either) yet in the book. I'm not the brightest bulb in the pack but I thought for sure I could figure this out - WRONG!

Where did you calculate the last payment and total interest? What variables did you use for them? Just output them.

Since I'm not an accountant and I don't know the equations themselves, I can give you basic ideas on the program flow.

Ask for:
Total to borrow (principal)
Interest rate (interest)
Length of loan (length)

With those 3 you can get the minimum monthly payment using one of the equations.
Ask for the payment they want. Of course, this will change the length of the loan, so you won't need that anymore.

Now start a while loop until principal <= 0
Calculate the payment on principal.
From that get all the other values for the month (interest paid, new balance, accumulated payment and interest)
Print a line of your amortization chart.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.