Calculator Question

1. Help? Guest

## Calculator Question

2. tj
Senior Member
Join Date
Dec 1969
Posts
172

## Try using some naming conventions

3. Medieval Dude Guest

## Good gravy!

Was I just looking at the code to The Matrix there? Please cut down to the bear essentials of the code and what specific problems yer having. I doubt too many people will want to take the time to go out to another site and try to compare what&#039;s going on to all this code. This will help us to help you much faster.

4. Help? Guest

## ok.

Well, here is the math part of the code which I am having trouble with.<BR><BR>&#060;%<BR>Dim y, x<BR>Dim Inc<BR>Dim Total<BR>Dim Fund<BR><BR>salary = Request.Querystring("salary")<BR>retiresal = Request.Querystring("retiresal")<BR>yrsb = Request.Querystring("yrsb")<BR>yrsa = Request.Querystring("yrsa")<BR>plan = Request.Querystring("plan")<BR>infla = Request.Querystring("infla")<BR>rassets = Request.Querystring("rassets")<BR>ans = Request.Querystring("ans")<BR><BR><BR>Inc = salary<BR>Total = salary<BR><BR><BR>For i = 1 to (yrsb - 1)<BR> Inc = Inc + Inc*(infla/100)<BR> Total = Total + Inc<BR>Next<BR><BR><BR>Fund = yrsa*(Inc)*(retiresal/100)<BR>x = Fund<BR><BR>y = x<BR><BR>For i = 1 to yrsb<BR> y = y - (x/(1+plan/100)^(yrsb-i))<BR>Next<BR>ans = y/12<BR><BR><BR><BR><BR>%&#062;<BR><BR>I changed the naming conventions a little to make it easier. I apologize, but as I said before, this was straight off of paper.<BR><BR>The website I directed you to has the correct results, these were not correct.. this math yields a large negative number :(<BR><BR>I believe the only problem is this part of the code:<BR><BR>y = y - (x/(1+plan/100)^(yrsb-i))<BR><BR>The main function of this part is to factor in the % they chose of the 401k plan and go backwards from the total number we have and determine how much they must save per month.. if anyone knows their stuff, this would be so greatly appreciated.<BR><BR><BR>

5. Medieval Dude Guest

## RE: ok.

I can&#039;t quite follow all yer variables. What&#039;s yrsa, yrsb, plan, infla, etc.? I don&#039;t know quite what these correspond to. If you could explain in plain words the logic you want, I&#039;m sure we could spit it out for you. For example:<BR>Take the sum of their salary, multiply that by the square root of their withheld amount, etc.

6. Help? Guest

## RE: ok.

Salary = salary<BR><BR>retiresal = The percentage of their salary they are getting now that they would like to get per year when they retire. (ie. 50,000 per year now would equal 40,000 per year if they chose %80)<BR><BR>yrsb = how many years before retirement<BR><BR>yrsa = how many years after retirement<BR><BR>plan = how much % they will earn in a 401k plan per year<BR><BR>infla = inflation per year<BR><BR>assets = current assets<BR><BR>ans = the answer, which is the monthly amount they should put into their 401k plan per month in order to hit their goal<BR><BR>So what we&#039;re trying to do is to get this to output how much per month they should put in their 401k plan. The hardest part is figuring out how that would work with the interest they will receive on their account per year. Basically, I have to backtrack from the total they would have after their working career and find how much they would need to put into a 401k plan per month that will be receiving the interest they inputted (variable plan)<BR><BR><BR>Does that help at all?<BR><BR>

7. Medieval Dude Guest

## RE: ok.

8. Medieval Dude Guest

## Here's what I've got so far...

You do away with that Total variable, as far as I can tell. You calculate Inc fine, which gives you the total amount that person has earned in salary before retiring. Now, to find out how much the person needs for the rest of his/her life, you&#039;ll need this logic:<BR>Amount_Needed = years_after_retirement * (Inc / years_before_retirement) * (desired_annual_percentage / 100)<BR>So, if the person earned 5000 dollars over 10 years, and they plan on living 10 years after retiring, and they want 80% of their income, the math would look like:<BR>Amount_Needed = 10 * (5000 / 10) * (80 / 100)<BR>which calculates to:<BR>Amount_Needed = 4000<BR>The logic you had didn&#039;t work quite right. Now, I&#039;m still working on the second part, so be patient...

9. Medieval Dude Guest

## As for the second logic part...

This is messy, messy, messy! I thought I could do it in a short time period, but I know now that it would probably take me much longer. Maybe yer logic is already correct. I don&#039;t know for sure. But if not, this should get you started on a new way of thinking. <BR>Basically, if there was no growth with 401K, the logic would be simple. Take the amount_needed divided by years_before_retirement divided by 12. Bang. Simple.<BR>With 401K growth, things get ugly. Let&#039;s say the person only works 1 year. Then the equation to find the annual amount they need would be this, where x represents the annual_amount they save):<BR>x + (x * (401Kpercent / 100)) = amount_needed<BR>If the person worked 2 years before retirement, the equation becomes hairier, so let&#039;s subsitute x + (x * (401Kpercent / 100)) with u:<BR>u + u + (u * (401Kpercent / 100)) = amount_needed<BR>which simplifies to<BR>2u + (u * (401Kpercent / 100)) = amount_needed<BR>Starting to see a pattern? Well, there&#039;s one there, but it&#039;s really messy. I would suggest spending some time going through the mathematics of this. Then, once you have the pattern figured out, transform it into one logic statment to find x, despite the other variables. But, if you know yer logic for that last part is correct, no need to bother. This won&#039;t be fun - just to warn you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•