I am solving a problem that has to do with Fibonacci numbers but ive been stuck for the longest time trying to figure this out. Given a specified “distance” from the golden ratio, I have to determine how
many Fibonacci numbers need to be generated in order to get this close.
How do I store these values into a string variable?
fib1 = 0
fib2 = 1
fib3 = fib1 + fib2
Here is my the code I have so far for the whole question, im quite confused and lost
Code:Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click 'declare variables Dim input As Double Dim fib1 As Integer Dim fib2 As Integer Dim fib3 As Integer Dim ratio As Double Const GOLDEN_RATIO As Double = 1.618 'assign user input input = Val(inputTextBox.Text) 'assign fibonacci numbers fib1 = 0 fib2 = 1 fib3 = fib1 + fib2 Dim display As String = "Fibonacci numbers generated:" & ControlChars.NewLine ratio = GOLDEN_RATIO - input Do fib2 = fib3 fib3 = fib1 + fib2 display &= ", " & fib3 Loop Until ratio = GOLDEN_RATIO input = Math.Abs(GOLDEN_RATIO - ratio) End Sub End Class




Reply With Quote