# Finanical Planner

## Program Listing

• This program will help a person plan his financial future.
• The program has a menu with three options:
• (1) Solve for the future value of an investment.
• (2) Solve for the monthly payment into the investment.
• (3) Solve for the number of years of the investment.

### FinancialPlanner.cpp

 ```/************************************************************************ * * * Program: FinancialPlanner * * * * Purpose: This program will help you plan for retirement * * * ************************************************************************/ #include #include #include using namespace std; int main() { // Get the user's menu choice cout << "Welcome to the Financial Planner" << endl << endl; cout << "Work now -- Play later!" << endl << endl; cout << "Choose one:" << endl; cout << "(1) Solve for future value" << endl; cout << "(2) Solve for monthly payment" << endl; cout << "(3) Solve for number of years" << endl; cout << endl << "Enter your menu choice (1, 2, or 3): " << flush; int Choice; cin >> Choice; // Validate menu choice if (Choice < 1 || Choice > 3) { cerr << endl << "Jeez! Can't you do anything right?!" << endl; cerr << "Exiting..." << endl; exit(1); } // Get the known quantities double PV; double FV; double t; double r; // Get the future value if (Choice != 1) { cout << "Enter the future value: " << flush; cin >> FV; } // Get the monthly payment if (Choice != 2) { cout << "Enter the monthly payment: " << flush; cin >> PV; PV *= 12; } // Get the number of years if (Choice != 3) { cout << "Enter the number of years: " << flush; cin >> t; } // Get the interest rate cout << "Enter the interest rate (as percent): " << flush; cin >> r; r /= 100; // Solve for the missing quantity switch (Choice) { // Solve for future value case 1: if (r == 0) FV = PV * t; else FV = PV * (pow(1 + r, t) - 1)/r; cout << endl << "The future value is \$" << FV << endl; break; // Solve for present value case 2: if (r == 0) PV = FV / t; else PV = FV / (pow(1 + r, t) - 1) * r; PV /= 12; cout << endl << "The monthly payment is \$" << PV << endl; break; // Solve for number of years case 3: { if (r == 0) t = FV / PV; else t = log(1 + r*(FV/PV)) / log(1 + r); int months = round(12*t); int years = months / 12; months %= 12; cout << endl << "The time required is " << years << " years "; cout << "and " << months << " months" << endl; break; } // This should never happen default: cerr << endl << "Houston, we have a problem" << endl; break; } return 0; }```

### Sample Run #1

 ```Welcome to the Financial Planner Work now -- Play later! Choose one: (1) Solve for future value (2) Solve for monthly payment (3) Solve for number of years Enter your menu choice (1, 2, or 3): 1 Enter the monthly payment: 200.00 Enter the number of years: 40 Enter the interest rate (as percent): 8.00 The future value is \$621736 ```

### Sample Run #2

 ```Welcome to the Financial Planner Work now -- Play later! Choose one: (1) Solve for future value (2) Solve for monthly payment (3) Solve for number of years Enter your menu choice (1, 2, or 3): 2 Enter the future value: 1000000 Enter the number of years: 40 Enter the interest rate (as percent): 8.00 The monthly payment is \$321.68 ```

### Sample Run #3

 ```Welcome to the Financial Planner Work now -- Play later! Choose one: (1) Solve for future value (2) Solve for monthly payment (3) Solve for number of years Enter your menu choice (1, 2, or 3): 3 Enter the future value: 1000000 Enter the monthly payment: 250 Enter the interest rate (as percent): 8.00 The time required is 43 years and 2 months ```