#include #include #include void pause () { cout << endl << "Hit any key to continue..."; getch (); } int main () { double cost, payment, balance, last_payment, interest, total_interest; int interest_rate, months; for (;;) { cout << "Enter of cost of car and payment: "; cin >> cost >> payment; if ((cost >= 1000) && (payment > (cost * 0.01))) { break; // we've got valid inputs } cout << "Invalid inputs - please try again." << endl; } cout << endl << " Rate Months Last Payment Total Interest" << endl << "--------------------------------------------------" << endl; for (interest_rate = 0; interest_rate <= 10; interest_rate++) { total_interest= 0; balance = cost; months = 0; while (balance > 0) { // compute interest payable for this month interest = balance * ((interest_rate / 12.0) / 100.0); interest = int((interest * 100) + 0.5) / 100.0; // round to nearest cent // increase balance owing the the interest balance += interest; // keep track of total interest paid total_interest += interest; // work out this month's payment and update the balance owing if (balance <= payment) { // this is our last payment last_payment = balance; // remember amount of last payment balance = 0; // car is now all paid off } else { // just another month balance -= payment; } months++; } cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2) << setw(4) << interest_rate << setw (9) << months << setw(16) << last_payment << setw(16) << total_interest<< endl; } pause(); return 0; }