So I'm a beginner at programming in general and am using TI-BASIC as an introduction. Right now I have been making sense of recursion in chapter 4 as best as I can.
Let me first say that this topic is especially frustrating because the concept itself makes sense when it is explained, but when the author says to go ahead and test your comprehension by translating the Fibonacci solver into a recursive program I become lost.
So after many failures I decided to step back and research more general information on both recursion and the Fibonacci sequence. Then after I mulled over the subject for some time I attempted it again, and, after more painful experimentation I came up with a program that seems to actually work . Now I must say my understanding is still somewhat tenuous so I'll type out the code I came up with and if anyone has any suggestions I'd be happy to consider them so that I get a better grasp on recursion.
Here's the driver function:
PROGRAM:FIBORECC
:Disp "CALCULATES NTH","FIBONACCI NUM
:Prompt N
:If N=1 or N=2
:Then
:Pause 1
:Else
:prgmZFIB
:Disp F
Here's the subprogram or whatever you want to call it:
PROGRAM:ZFIB
:If N=2
:Then
:1→A
:1→B
:Else
:A+B→F
:B→A
:F→B
:N-1→N
:prgmZFIB
:End
When I came up with this I thought for sure it wouldn't work but it did. It still feels like maybe I'm missing something but for now at least it functions. I look forward to continuing my studies with this book as a guide.
Let me first say that this topic is especially frustrating because the concept itself makes sense when it is explained, but when the author says to go ahead and test your comprehension by translating the Fibonacci solver into a recursive program I become lost.
So after many failures I decided to step back and research more general information on both recursion and the Fibonacci sequence. Then after I mulled over the subject for some time I attempted it again, and, after more painful experimentation I came up with a program that seems to actually work . Now I must say my understanding is still somewhat tenuous so I'll type out the code I came up with and if anyone has any suggestions I'd be happy to consider them so that I get a better grasp on recursion.
Here's the driver function:
PROGRAM:FIBORECC
:Disp "CALCULATES NTH","FIBONACCI NUM
:Prompt N
:If N=1 or N=2
:Then
:Pause 1
:Else
:prgmZFIB
:Disp F
Here's the subprogram or whatever you want to call it:
PROGRAM:ZFIB
:If N=2
:Then
:1→A
:1→B
:Else
:A+B→F
:B→A
:F→B
:N-1→N
:prgmZFIB
:End
When I came up with this I thought for sure it wouldn't work but it did. It still feels like maybe I'm missing something but for now at least it functions. I look forward to continuing my studies with this book as a guide.