# Help....

Printable View

• 11-14-2003
P3st
Help....
I have this problem that has been troubling me. The problem is as follow:

If interest is compounded annually, it grows as follows. Suppose P0 is the initial amount and INT is the rate per year. If P1, P2, and P3 is the balance at the end of first, second, and third year, respectivey, then

P1 = P0 + P0 * INT = P0 * (1 + INT)
P2 = P1 + P1 * INT = P1 * (1 + INT) = P0*(1 + INT) * (1 + INT)
= P0 * (1 + INT)^2
P3 = P2 + P2 * INT = P2 * (1 + INT) + P0 * (1 + INT) * (1 * INT) * (1 + INT) = P0 * (1 + INT)^3

and so on.

When money is deposited in an IRA account it is usually sheltered from taxes until the money is withdrawn after the age of 59. Suppose that someone dear to you opened such and account for you on your sixteenth birthday at 10% interest and that he or she forgot about it (so no money was added or withdrawn). On your sixtieth birthday, you are notified about this account by some fortune hunters. The money has been compounded at the 10% rate. Write a program that reads an initial amount and computes the total in the account on your sixtieth birthday.

You decide to leave the money in for another year. Starting from your sixty-first birthday, you decide to withdraw each year's interest income. In other words, you withdraw the interest and leave the rest of the money untouched . How much income per month for the rest of your life would you have?

Design your program to accept any integer input. Test it with initial investments of: \$1700, \$3600, and \$8500.

(Note: Use a loop to compute the amount at your sixtieth birthday. Do not use the predefined function pow .)

The program should do all the computing needed, and ouput all the relevant data as follows:

The initial investment was \$______. The total amount accumulated after ______ years, if \$______ is allowed to compound with an interest of 10.00%, comes to \$_______.
The total amount accumulated after ______ (years + 1) years, if \$ _________ is allowed to compound with an interest of 10%, comes to \$ _______.
The interest earned during the year is \$ ______. If interest is withdrawn each year thereafter, my income is \$ _______ per month.

i WAS WONDERING IF ANYONE COULD GIVE ME SOME POINTERS ON HOW TO GO ABOUT SOLVING THIS PROBLEM (NOT THE ANSWER) :D THANKZ...
• 11-14-2003
Salem
I think its just
p = p * 1.1;

repeated as many times as you need (say 59 times)
• 11-14-2003
DougDbug
Start with a plan... an idea of how your program is going to "flow"
I usually start-out with an outline... sometimes I make a rough flow chart.

Basically, I start-out with a program that's nothing but comments explaining what the code needs to do, then start adding code a little at a time. I test-compile and test-run as I go along.

// Define variables & constants
// Amount
// Interest Rate
// Number of years

// Get user's input

// Calculate in loop

// Display results

You can fill-in the details. Start-out with a one-year non-looping calculation, then add the loop when you have that working.

And, you only need one balance variable... because C++ statements are not mathmatical equations... you CAN have:
Balance = Balance + Interest // Update Balance
This is NOT a valid math equation, but it IS a valid C++ statement which assigns a new value to Balance.
• 11-16-2003
P3st
I gave some thought to what was mention and this is what i came up with ->

Code:

```#include <iostream> #include <iomanip> using namespace std; const double INT = 0.10; int main() {         int years=0, x=0;         double P0=0, Px=0, P1=0, interest=0;         cout << fixed << showpoint;         cout << setprecision(2);         cout << "Program that reads an initial amount and computes "                 << "the total in the account on your sixtieth birthday." << endl << endl;         cout << "Enter the initial amount of the account -> ";         cin >> P0;         Px = P0;         cout << "Enter the amount of years the account remain untouch -> ";         cin >> years;                 cout << endl << endl;         cout << "The initial investment was \$" << P0 << " . The total amount accumulated after "                 << years <<" years, if \$" << P0 << " is allowed to compound with an interest of 10.00%,"                 << "comes to \$";                 for (x = 0; x != years; x++)                 {                         P1 = P0 + ( P0 * INT);                         while (P0 < P1)                                 P0 = P1;                 }         cout << P1 <<'.' << endl << endl;         cout << "The total amount accumulated after " << years << " (years + 1) years,"                 <<" if \$" << Px << " is allowed to compound with an interest of 10%, comes to \$";                 years += 1;         for (x = 0; x != years; x++)                 {                         if (x == years - 1)                                 interest += (Px * INT);                                P1 = Px + ( Px * INT);                         while (Px < P1)                                 Px = P1;                 }         cout << P1 << " ." << endl << endl;         cout << "The interest earned during this year is \$" << interest                 << ".If interest is withdrawn each year thereafter, my income is \$"                 << (P0 / 12) << " per month." << endl << endl;                 return 0; }```
I was wondering it anyone can make any comment or mention anyways of improving the program to make it more efficient.
THANKZ :D