grifjason

07-12-2007, 01:11 AM

// This program will tell you how many months it will take

// you to pay off the loan, as well the total amount of interest

// paid over the life of the loan.

#include <iostream>

using namespace std;

int main()

{

double loan_amount, interest, amt_left, interest_paid = 0,

interest_rate = .015, last_payment;

int monthly_payment = 50, num_months = 0;

cout << "What is the amount of the loan: ";

cin >> loan_amount;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

while (loan_amount > 0)

{

cout << loan_amount << endl;

interest = interest_rate * loan_amount;

amt_left = monthly_payment - interest;

loan_amount = loan_amount - amt_left;

interest_paid = interest_paid + interest;

num_months++;

}

cout << loan_amount << endl;

cout << num_months << endl;

cout << interest_paid << endl;

return 0;

}

I need help with handling the last payment. I cant figure out if I need another loop or if I can adjust my condition to make it work. There is $47.12 left over, and I would like to know how to handle it.

Appreciate the help.

// you to pay off the loan, as well the total amount of interest

// paid over the life of the loan.

#include <iostream>

using namespace std;

int main()

{

double loan_amount, interest, amt_left, interest_paid = 0,

interest_rate = .015, last_payment;

int monthly_payment = 50, num_months = 0;

cout << "What is the amount of the loan: ";

cin >> loan_amount;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

while (loan_amount > 0)

{

cout << loan_amount << endl;

interest = interest_rate * loan_amount;

amt_left = monthly_payment - interest;

loan_amount = loan_amount - amt_left;

interest_paid = interest_paid + interest;

num_months++;

}

cout << loan_amount << endl;

cout << num_months << endl;

cout << interest_paid << endl;

return 0;

}

I need help with handling the last payment. I cant figure out if I need another loop or if I can adjust my condition to make it work. There is $47.12 left over, and I would like to know how to handle it.

Appreciate the help.