Hi,
I have written a vb code for the Monte Hall Problem(in my case I have used the example of 3 cards - one of the card is red and 2 are black, you have to choose red to win) But I am not getting the desired results as expected.
Could someone point out my mistakes or advice me where I have gone wrong in my code.
I have attached my vb code with this thread.
vb.net Code:
Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ThreeCardMonte() End Sub Sub ThreeCardMonte() Randomize() Dim cards(0 To 2) As Integer ' 1 means a red card , 0 means a black card anywhere in the 3 card stack Dim switchwins As Integer = 0 Dim staywins As Integer = 0 Dim winner_redcard As Integer Dim games As Integer Dim choice As Integer Dim shown_card As Integer For games = 1 To 100 Randomize() winner_redcard = CInt(Int((2 * Rnd()) + 0)) cards(winner_redcard) = 1 ' randomly place the winning red card in the card stack choice = CInt(Int((2 * Rnd()) + 0)) Do shown_card = CInt(Int((2 * Rnd()) + 0)) Loop While ((cards(shown_card) = 1) Or (shown_card = choice)) staywins = staywins + Int(cards(choice)) ' the case where you won by staying with your choice Dim temp As Integer temp = choice + shown_card switchwins = switchwins + Int(cards(2 - (temp))) ' the case where win by switching cards(winner_redcard) = 0 ' reset the winning card for the next round of game Next Debug.Print("Switchwins = ") Debug.Print(switchwins) Debug.Print("Staywins = ") Debug.Print(staywins) End Sub End Class




Reply With Quote