Solved

ANOTHER C++ QUESTION

Posted on 2013-07-01
7
211 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 19

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 51

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 32

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 51

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 51

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now