/********************************************** * * * * * CSCI 1470, Fall 2005 * * Machine Problem: MP4 * * Purpose: Calculate monthly payment, * * annual interst, and duration of a loan * **********************************************/ #include #include #include using namespace std; int main(void) { //Declare the variables double monthlypayment, loanamount, monthlyinterest, annualinterest; int numbermonths, numberyears; //Get data from user with prompt cout << "Enter the amount of loan in U.S. dollars:"; cin >> loanamount; cout << endl; cout << "Enter the rate of interest per year(nominal rate):"; cin >> annualinterest; cout << endl; cout << "Enter the duration of loan in years:"; cin >> numberyears; cout << endl; // Calculate the monthly interest and payment monthlyinterest = annualinterest/1200; numbermonths = numberyears * 12; monthlypayment = ( monthlyinterest * loanamount * pow((1 + monthlyinterest),numbermonths) ) / ( pow((1 + monthlyinterest),numbermonths) - 1 ); //Display the results cout << "Amount of loan is: $" << loanamount << " (U.S. dollars)" << endl << endl; cout << "Rate of interest per year is: " << annualinterest << " (nominal rate expressed as percent)" << endl << endl; cout << "The duration of the loan is: " << numberyears << " (years)" << endl << endl; cout << "The monthly payment is: $" << setprecision(2) << fixed << monthlypayment << " (rounded to two decimal places)" << endl << endl; return 0; }//end of function main