Solved

ANOTHER C++ QUESTION

Posted on 2013-07-01
7
217 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
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 54

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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 33

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 54

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 54

Expert Comment

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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.

777 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