I figured it out heres the full code for the working program
Code:Public Class GoldenRatioForm 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 Dim ans As Double Dim counter As Integer Const GOLDEN_RATIO As Decimal = 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 display &= fib1 & ", " & fib2 & ", " & fib3 'declare ratio and counter ratio = fib3 / fib2 ans = Math.Abs(GOLDEN_RATIO - ratio) counter = 3 'Implement Loop Do While (ans >= input) fib1 = fib2 fib2 = fib3 fib3 = fib1 + fib2 ratio = fib3 / fib2 ans = Math.Abs(GOLDEN_RATIO - ratio) display &= ", " & fib3 counter += 1 Loop 'assign answer to List Box fibListBox.Text = display counterLabel.Text = counter End Sub End Class




Reply With Quote