I am more or less new to VB.NET and I am trying to program a simple console application for a basic finance and savings calculation program.
I am having trouble with the Math.Log() function and I hope someone can help me to point out my mistake/mistakes.
This is the values I need to get working (the brackets shows the values that actually should work but do not in my code):
Public Class basicSavingsPlaner
Private userTotalCost As Double (50,000.00)
Private userSaves As Double (3,451.47)
Private userAnnualRate As Decimal (0,08)
Private userMonths As Double (should be 10)
If I use my regular calculator (TI-82) I get the correct answer of userMonths which is 10, this is how I type it on my calculator (I switched the values from digits to the names of my Declarations):
(log(((userAnnualRate * userTotalCost)/userSaves)+1)/(log(1+userAnnual)) = 10.0029...
This is my attempt to recreate it for my VB.NET console application:
userMonths = ((Math.Log((userAnnualRate * userTotalCost) / userSaves) + 1) / (Math.Log(1 + userAnnualRate)))
In this case, userMonths's result is 14.9, which is wrong.
I would really appreciate if someone could help me, I have search here in this forum and on Google for days now.
// Televeinken
If you look closely at the statement from your TI-82 and compare it with your VB.Net code you will see that you have the statement grouped differently between the two. Try something like this(note the grouping of three brackets after the initial log statement instead of two):
userMonths = (Math.Log(((userAnnualRate * userTotalCost) / userSaves) + 1) / (Math.Log(1 + userAnnualRate)))
userMonths = 10.000008962349851