/************************************************************************ *Low Monthly payments *Jason Calcagno *Input: principle: amount borrowed (in dollars) *Output: monthlyPayment (in dollars and cents) *AP/IB computer science *10/6/02 *************************************************************************/ #include #include #include double monthlyPayment ( double principle, double annualRate, int numYears ); void main () { double principle, // Amount borrowed (in dollars) interestRate; // Annual interest rate (as a % of 1.0) int numYears; // Length of the loan (in years) // Prompt the user and read in the amount borrowed, interest // rate, and length of the loan. cout << endl << "Enter the amount borrowed: "; cin >> principle; cout << "Enter the annual interest rate (as a % of 1.0): "; cin >> interestRate; cout << "Enter the length of the loan (in years): "; cin >> numYears; // Output the monthly payment. cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout << setprecision (2); cout << "Monthly payment : $ " << monthlyPayment(principle,interestRate,numYears) << endl; } //-------------------------------------------------------------------- // Insert your monthlyPayment() function here. //-------------------------------------------------------------------- double monthlyPayment ( double principle, double annualRate, int numYears ) { double months = numYears*12; double mpr = annualRate/12; double monthlyPayment = mpr*((principle/(1-(1/(pow (1 + mpr, months)))))); return monthlyPayment; } /* Enter the amount borrowed: 1000 Enter the annual interest rate (as a % of 1.0): .1 Enter the length of the loan (in years): 1 Monthly payment : $ 87.92 Press any key to continue Enter the amount borrowed: 5000 Enter the annual interest rate (as a % of 1.0): .05 Enter the length of the loan (in years): 2 Monthly payment : $ 219.36 Press any key to continue Enter the amount borrowed: 10000 Enter the annual interest rate (as a % of 1.0): .089 Enter the length of the loan (in years): 10 Monthly payment : $ 126.14 Press any key to continue */