/*********************************************** * * * * * CSCI 1470, Fall 2005 * * Machine Problem: MP8ab * * Purpose:Annuities with menu * ***********************************************/ #include #include #include //display menu void menu(); //calculate future annuity void fuvannuity(); //calculate present annuity void pvannuity(); //show ammortization schedule void amschedule(); using namespace std; int main(void) { menu(); return 0; }//end of function main //This function displays the menu void menu() { int menu_select; cout << "1. Future Value of an Annuity" << endl; cout << "2. Present Value of an Annuity" << endl; cout << "3. Monthly Payment of a Loan and Amortization Schedule" << endl; cout << "4. Exit" << endl << endl; cout << "Please enter your selection: "; cin >> menu_select; if (menu_select < 5) switch (menu_select) { case 1: fuvannuity(); break; case 2: pvannuity(); break; case 3: amschedule(); break; case 4: return; } return; }//end of function menu //Calculate and display the future value of an annuity void fuvannuity() { double fv, pmt, i; int n; cout << "Enter the fixed periodic payment: "; cin >> pmt; cout << endl << "Enter the periodic interest rate: "; cin >> i; cout << endl << "Enter the number of periods: "; cin >> n; fv = pmt * (((pow((1 + i),n)) - 1) / i); cout << endl << endl << "The Future Value of the Annuity is " << fv << endl << endl; return; }//end of function fuvannuity //Calculate and display the present value of an annuity void pvannuity() { double pv, pmt, i; int n; cout << "Enter the fixed periodic payment: "; cin >> pmt; cout << endl << "Enter the periodic interest rate: "; cin >> i; cout << endl << "Enter the number of periods: "; cin >> n; pv = pmt * ((1 - pow((1 + i),-n)) / i); cout << endl << endl << "The Present Value of the Annuity is " << pv << endl << endl; return; }//end of function pvannuity //Calculate and display the monthly payment of a loan and display the ammortization schedule void amschedule() { double pmt, pv, i, remain; int n; cout << "Enter the present value of the annuity: "; cin >> pv; cout << endl << "Enter the periodic interest rate: "; cin >> i; cout << endl << "Enter the number of years: "; cin >> n; //changes n from years to months n = n * 12; remain = pv; cout << setw(5) << "Payment#" << setw(20) << "Monthly Payment" << setw(23) << "Interest" << setw(26) << "Remaining Loan" << endl; cout << setw(5) << "--------" << setw(20) << "---------------" << setw(23) << "--------" << setw(26) << "--------------" << endl; double i_dec; i_dec = i / 1200; pmt = (pv * i_dec) / (1 - pow((1 + i_dec),-n)); for (int j=0; j