Re: Fibonacci Help, Im stuck
what is the use of storing them as a string?
just for display sake? or to tokenize them for later UN-Stringing them?
(surprisingly, everything else i understood)
Re: Fibonacci Help, Im stuck
I guess to send them as a display to the multiline textbox i will be using to show the fibonacci numbers that had to be used
Re: Fibonacci Help, Im stuck
You already have them stored as a string in "Display".
i just don't know if you want ControlChars.NewLine or VBCRLF (vb carriage return line feed)
textbox.text = display
Re: Fibonacci Help, Im stuck
ah so i did do that right under the 'assign fibonacci numbers?
I do want them as ControlChars.NewLine well at least I think I do. Im honestly having hell of a time with this, when i try to run it to see what happens it just crashes
Re: Fibonacci Help, Im stuck
Ier t says that after doing fib2 = fib3
fib3 = fib1 + fib2
Now store the “new” fib3 before calculating the next number.
2. You can store this information in a variable of String data type.
Yes this is homework but im trying really hard and posting my own code to see whats wrong and how I can fix it. I believe this way is the right way to do it without mods frowning upon me? And also learning in the process
Re: Fibonacci Help, Im stuck
I got sidetracked by something in your code.
fib2 = fib3
fib3 = fib1 + fib2
display &= ", " & fib3
wouldn't this end up being 1 + 2 = 3 , 1 + 3 = 4, 1+4 = 5 ?
shouldn't it be :
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
i might be wrong and just really tired.
Re: Fibonacci Help, Im stuck
hmm that part i got straight from the question it confused me even more though so it might be wrong. So should I just do my loop with the fib1 = 0 fib2 = 1 fib3 = fib1 + fib2 or how would I do he loop to see how ay fibonacci numbers it would take to get the golden ratio that distance away? (from the user input)
Re: Fibonacci Help, Im stuck
.
check this link
fib1 = 0
fib2 = 1
fib3 = fib1 + fib2
....
fib1 = fib2
fib2 = fib3
fib3 = fib1+fib2
where does it crash?
your output sounds like you just need a textbox and have that TextboxName.Text = display
Re: Fibonacci Help, Im stuck
found your crash
Do
fib2 = fib3
fib3 = fib1 + fib2
display &= ", " & fib3
Loop Until ratio = GOLDEN_RATIO
it will loop forever if your Fibonacci is wrong and you never hit a golden ratio. that's the crash.
Re: Fibonacci Help, Im stuck
Ah ya i figured that's where the problem was but I wasnt quite sure how to fix that. I fell asleep at my computer like a good student lol
Re: Fibonacci Help, Im stuck
Here is my updated code (doesnt crash) until now but there is something wrong with my loop math part because i dont get the answeres im supposed to be getting.
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
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
display &= fib1 & ", " & fib2
Do
fib1 = fib2
fib3 = fib1 + fib2
ratio = fib3 / fib2
ans = ratio - input
display &= ", " & fib3
Loop Until ans >= GOLDEN_RATIO
input = Math.Abs(GOLDEN_RATIO - ratio)
fibListBox.Text = display
End Sub
End Class
Re: Fibonacci Help, Im stuck
Re: Fibonacci Help, Im stuck
I'm guessing that's a problem *__* my name is newvbusernoob for a reason I guess.
Re: Fibonacci Help, Im stuck
Isn't that a continuation after I declared the first two Fibonacci numbers? I'm not sure. I'm having a problem with that math/logic in
my loop
Re: Fibonacci Help, Im stuck
Well it is, but it's nothing to do with code. It's pure arithmetic. When fib1 = 0, fib 2 = 1 so ....
vb.net Code:
fib1 = fib2 ' now fib1 = 1, fib2 = 1
fib3 = fib1 + fib2 ' fib3 = 2
I haven't studied your code in depth but surely what you should be doing is
vb.net Code:
fib1 = fib2
fib2 = fib3
fib3 = fib1 + fib2
Re: Fibonacci Help, Im stuck
Quote:
Originally Posted by
Waxy
.
check this
link
fib1 = 0
fib2 = 1
fib3 = fib1 + fib2
....
fib1 = fib2
fib2 = fib3
fib3 = fib1+fib2
where does it crash?
your output sounds like you just need a textbox and have that TextboxName.Text = display
....
Re: Fibonacci Help, Im stuck
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