Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ANOTHER C++ QUESTION

Posted on 2013-07-01
7
Medium Priority
?
232 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 60

Accepted Solution

by:
Julian Hansen earned 1600 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Assisted Solution

by:sarabande
sarabande earned 400 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 60

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 60

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

824 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