Someone help please, Im trying to create a program where the user enters in a certain amount of money and I recursively, tell them how many ways they can make change from that amount of money. I dont have to state what the change is just how many different ways. Heres wut i got
Code:Dim ways As Integer Private Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStart.Click Dim cash As Double cash = CDbl(txtInput.Text) If (cash <= 0) Then lblOutput.Text = ("You must have a positive amount of money to make change") Else Change(cash) lblOutput.Text = ("There are " & ways & " to make change from $" & cash & ".") End If End Sub Private Sub Change(ByVal cash As Double) Dim newcash As Double If (cash >= 2.0) Then newcash = cash - 2 Change(newcash) End If If (cash >= 1.0) Then newcash = cash - 1 Change(newcash) End If If (cash >= 0.25) Then newcash = cash - 0.25 Change(newcash) End If If (cash >= 0.1) Then newcash = cash - 0.1 Change(newcash) End If If (cash >= 0.05) Then newcash = cash - 0.05 Change(newcash) End If If (cash >= 0.01) Then newcash = cash - 0.01 Change(newcash) End If If (cash = 0) Then ways = ways + 1 End If End Sub Private Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click lblOutput.Text = ("") txtInput.Text = ("") ways = 0 End Sub End Class




Reply With Quote