#include #include #include #include void main (void) { double interest_rate, loan_amount, payment_amount, graduation_debt, debt; int study_years, payment_years, i; const int max_payment_years = 100; // we want all floating point ouput in dollars and cents cout << setprecision(2) << setiosflags (ios::fixed | ios::showpoint); cout << "Enter interest rate (in %, -ve to stop): "; cin >> interest_rate; while (interest_rate >= 0) { cout << "Enter loan and payment amounts: "; cin >> loan_amount >> payment_amount; // output table header cout << endl << " Study Years Graduation Debt Payment Years " << endl << "----------------------------------------------" << endl; for (study_years = 4; study_years <= 10; study_years++) { // compute debt at graduation graduation_debt = 0; for (i = 0; i < study_years; i++) { graduation_debt = (graduation_debt + loan_amount) * (1.0 + (interest_rate / 100.0)); } // compute years to pay debt = graduation_debt; payment_years = 0; while ((debt > 0) && (payment_years < max_payment_years)) { debt *= (1 + (interest_rate / 100.0)); debt -= payment_amount; payment_years++; } // output table line cout << setw(6) << study_years << setw(20) << graduation_debt << setw(15) << payment_years << endl; } // the endl leaves a blank line between the table and our prompt message cout << endl << "Enter interest rate (in %, -ve to stop): "; cin >> interest_rate; } }