Solved

ANOTHER C++ QUESTION

Posted on 2013-07-01
7
226 Views
Last Modified: 2013-07-15
I am creating a financial consule application to calculate deposits each month for 40 years at 0.07 interest.  The amount deposited per month is $300.00 for a total of 480 months.  I need to calculate that total, then take an annual payment of $91800 per year for 30 years from the total calculation.  With each annual withdrawal I want to calculate the new balance at .085 percent interest until the end of the 30 year period.  The problem I am having is that my code seems to show the inital calculation in exponent form, also when I take the annual payment it adds instead of subtracting from the balance.

The code for the first 40 years is below:

double  p(0), fvr(0.07), r(.085), fv(0), Pi(0), dep(300), pmt(91800);

 int     n(480), i(0), e(0), y(30);
 

   while( i != n )                            //  iterate  n  times
   {
      

         fv = fv * ( 1 + fvr )  +  dep;

             ++i ;          //increment to next period
   }

//----- Code for the remaining 30 years-----

    while( e != y )                            //  iterate  n  times
   {
      

         Pi  =  Pi * (1 + r ) - pmt;
        

             ++e ;          //increment to next period
   }

--------------------------------

Thanks in advance.

aj85
0
Comment
Question by:aj85
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 20

Expert Comment

by:n2fc
ID: 39291681
Do you really mean .07  interest PER MONTH?

You probably want to divide it by 12 to get monthly factor!

Probably why your money grew so fast!
0
 
LVL 56

Accepted Solution

by:
Julian Hansen earned 400 total points
ID: 39291839
To understand your problem:

You have a situation where you are depositing $300 / month for 480 months @ 7% p.a.

Do you then want to start withdrawals from the total account of $91800 / year for 30 years at 8.5%

Why can't you use the geometric formula here?

For the first bit
Sn = a(1-r^n)/1-r
So for your example that would be
S(480) = 300(1-(1+7%/12)^480)/(1-(1+7%/12)) = 787444

Don't understand the next bit - if you are going to be withdrawing $91800 / year against the 787444 amount with 8.5% interest - your account will be empty after around 13 years - so not sure where the 30 years comes into it

Or did I miss the boat ...
0
 

Author Comment

by:aj85
ID: 39292162
Hello Julian,

Well you are correct in your understanding.  The issue is that the interest on the first 40 years should be componded daily at the 7%.  Then when the annual withdrawal is made, the first 91800 should come from the principal balance, then what is remaining should be calculated at the 8.5%.

Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Assisted Solution

by:sarabande
sarabande earned 100 total points
ID: 39319990
The problem I am having is that my code seems to show the inital calculation in exponent form

to output a floating point value in decimal form, you may use appropriate formatting:

double mydouble = (123/100)*7;
int fraction = 2; 
// calling fixed + setprecision determines count of fraction (digits after decimal point)
std::cout << std::fixed << std::setprecision((size_t)fraction) << mydouble;

Open in new window


Sara
0
 
LVL 56

Expert Comment

by:Julian Hansen
ID: 39320512
Is there a reason you are not using the geometric fomula as outlined in my previous post?
0
 

Author Closing Comment

by:aj85
ID: 39327878
Thank you both for the quick and sound solution.  Julian, you were correct about the geometric formula solution.  Sara, thanks for the correct formatting as well.

Thanks,
AJ
0
 
LVL 56

Expert Comment

by:Julian Hansen
ID: 39328741
You are welcome - thanks for the points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question