Help on my assignment on programming, golden ratio and fibonacci numbers

  • Thread starter Thread starter SpecularThree55
  • Start date Start date
S

SpecularThree55

Guest
I've already got this much coded all this but I don't know what to do next. I've been provided a hint which says

1. Change the Text property of the form’s labels to match what is seen in the sample output at the end of this document.

2. For this project you need to declare only one constant: Const dblGOLDEN_RATIO As Double = 1.6180339887

3. The difference between the current ratio of the last two fibs and the golden ratio must be unsigned. To do this use the absolute value function as follows: dblDiff = Math.Abs(dblGOLDEN_RATIO - dblRatio)

4. After exiting the loop, display the fib numbers generated in the Text property of the txtDisplayFibs TextBox.

5. To determine how many Fibonacci numbers were generated you can set up a loop counter. You did this in ----; we gave the name intNumFibs to this memory location in ----.

I'm really lost and don't know what to do, i'm terrible at this stuff. I know I just need to add a change of few things but I don't know where/how. Any help will be much appreciated!!!


Public Class Form1

Private Sub btnFibs_Click(sender As Object, e As EventArgs) Handles btnFibs.Click

'declare Integer variables for user Input, fib1, fib2, fib3, and num fibs
Dim intUserInput As Integer
Dim intFib1 As Integer
Dim intFib2 As Integer
Dim intFib3 As Integer
Dim intNumFibs As Integer
'declare String variable to store all fibs generated
Dim strDisplay As String
'declare Boolean Flag to serve as loop termination condition
Dim blnFlag As Boolean
'collect user input from text property of txtUserinput
intUserInput = CInt(txtUserInput.Text)
'initialize variables to prepare for entering the loop
'set up teh first three fibs: 0, 1, 1
intFib1 = 0
intFib2 = 1
intFib3 = intFib1 + intFib2
'assign 3 to the num fibs variable, since we have 3 fibs before entering the loop
intNumFibs = 3
'format the String variable witht he info we have now
strDisplay = "Fibonacci numbers generated:" & vbCrLf
strDisplay &= intFib1 & "," & intFib2 & "," & intFib3
'initialize the Boolean cariable with the correct Boolean expression to it will correctly control the loop
blnFlag = (intNumFibs < intUserInput)

'implement loop to generate reamaining fibs
Do While blnFlag

'reassign the three fibs to get teh next fib num in intFib3
'the new fib1 is the old fib2
intFib1 = intFib2
'the new fib2 is the old fib3
intFib2 = intFib3
'the new fib3 is the sum of the new fib1 and the new fib2
intFib3 = intFib1 + intFib2
'increment intNumFibs by 1, since we now have 1 more fib
intNumFibs += 1
'append the newest fib to the String variable
strDisplay &= "," & intFib3
'update blnFlag so it will continue to correctly control when to exit the loop
blnFlag = (intNumFibs < intUserInput)
Loop

'display all fibs generated in Text property of txtDisplayFibs
txtDisplayFibs.Text = strDisplay
'display how many fibs in Text property of lblNumFibs
lblNumFibs.Text = intNumFibs.ToString()
End Sub
End Class

- James D. Varus

Continue reading...
 
Back
Top