I still am haaving trouble trying to get a least common denominator. I don't nessicarrily want someone to do the code just give me some direction on how to write it. I have included the code I have so far for the button click it works fine except that it will not do the reduction of the fraction answer. This is from a button click on a VB form.
Expand|Select|Wrap|Line Numbers
- Private Sub AddFract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFract.Click
- ' setting up my variables
- Dim num1add As Double = AddNum1.Text
- Dim num2add As Double = AddNum2.Text
- Dim den1add As Double = AddDen1.Text
- Dim den2add As Double = AddDen2.Text
- Dim numansadd As Double
- Dim denansadd As Double
- Dim WholeNumberadd As Double
- ' if denominators are different in text boxes then run this
- If den1add <> den2add Then
- 'creates the numerator of the answer
- numansadd = ((num1add * den2add) + (num2add * den1add))
- 'creates the denominator of the answer
- denansadd = (den1add * den2add)
- ' if denominators match run this
- Else
- ' adds the 2 numerators to create an answer
- numansadd = (num1add + num2add)
- ' keeps the matching denominators
- denansadd = (den1add)
- End If
- ' after adding if the numerator is higher that the denominatoer run this
- If numansadd >= denansadd Then
- ' setting variables
- Dim LoopCountadd As Integer
- Dim TimesLoopedadd As Integer
- TimesLoopedadd = 0
- LoopCountadd = 0
- ' a loop to subtract the denominator from the numerator until the numerator_
- ' is smaller than the denominator
- Do While numansadd >= denansadd
- ' subtracts the numerator from the denominator
- TimesLoopedadd = (denansadd - numansadd)
- ' counts up 1 for every time the numerator is subtracted from the denominator
- LoopCountadd += 1
- ' makes WholeNumber = the total of times the loop occurred
- WholeNumberadd = LoopCountadd
- ' makes the remainder = the new numerator answer
- numansadd = (numansadd - denansadd)
- ' goes back to see if the numerator is higher than the denominator
- Loop
- ' "this is where I want it to reduce"
- End If
- ' if the new numerator = 0 only the whole number is displayed
- If numansadd = 0 Then
- AddFractAns1.Text = "" & (WholeNumberadd)
- ' otherwise the whole number and the remaining fraction are displayed
- Else
- AddFractAns1.Text = "" & (WholeNumberadd) & " and " _
- & (numansadd) & "/" & (denansadd)
- End If
- End Sub
Thank you very much in advance for any help.