A man pays $1 to get into a gambling casino. He loses half of his money there and has to pay $1 to leave. He goes to a second casino and pays $1 to get in, he loses half his money again, and has to pay $1 to leave. Then, he goes to a third casino, pays another $1 to get in, loses half his money again, and pays $1 to leave. After this he's broke. ($0). Write a program to determine the amount of money he began with by testing $5, then $6, and so on.

Took me forever but I finally got it. This is the working code:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim x As Integer = 0

For y As Integer = 1 To Val(txtUserInput.Text) Step 1
x = 2 * x + 3

Next y

Me.lblOutput.Text = "He started out with $ " & x

End Sub
End Class

But now I'm supposed to figure out this...
The guy goes in the first casino, pays $1, loses half his money, pays $1 to get out. Goes into a second casino, pays $2, loses half his money, pays $2 dollars to get in. Third casino- pay $3, lose half, pay $3 ect.

How do I find the code for this ><!

8 Years
Discussion Span
Last Post by blackcat40

I'm sure you don't need this anymore but just in case your or anyone else does here it is.
I did mine a bit different. I did a loop that would run 3 time because we know he went in 3 different casinos. I also started at $0 and worked my way up by adding a dollar for the exit fee, doubling his money, then adding a dollar for the entry fee. So basically the equation:

money = (money + 1) * 2 + 1

would execute 3 times. As for the second part you need to have the fees increase by a dollar at each successive casino. So you should probably use a variable that increments at the end of each run of the loop.
I know most forums don't like people posting answers to homework, and I know that's what this is because I was assigned the same problem, but I will do everything I can to help without actually posting the code I used.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.