I have a simple recursive function to write in VBA that does the following : It must count the number of times we must take the log of a parameter 'x' to find log(x) < 1
Examples :
So I wrote it and it doesn't work as expected ! It always adds +1 to the result ! It looks like the last 'Else' block is always interpreted. Any help will be really appreciated
Function logcount(x As Double) As Integer
If x <= 0 Then
MsgBox "You must enter a positive value"
Exit Function
ElseIf Log(x) < 1 Then
logcount = 1
Else
logcount = 1 + logcount(Log(x))
End If
End Function
Log
in VBA is the natural logarithm.
Apparently you meant a base-10 logarithm:
Log10 = Log(X) / Log(10#)