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:
  1. Public Class Form2
  2.  
  3.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.  
  5.         ThreeCardMonte()
  6.  
  7.     End Sub
  8.  
  9.     Sub ThreeCardMonte()
  10.         Randomize()
  11.         Dim cards(0 To 2) As Integer ' 1 means a red card , 0 means a black card anywhere in the 3 card stack
  12.         Dim switchwins As Integer = 0
  13.         Dim staywins As Integer = 0
  14.         Dim winner_redcard As Integer
  15.         Dim games As Integer
  16.         Dim choice As Integer
  17.         Dim shown_card As Integer
  18.  
  19.         For games = 1 To 100
  20.             Randomize()
  21.  
  22.             winner_redcard = CInt(Int((2 * Rnd()) + 0))
  23.             cards(winner_redcard) = 1 ' randomly place the winning red card in the card stack
  24.             choice = CInt(Int((2 * Rnd()) + 0))
  25.  
  26.             Do
  27.                 shown_card = CInt(Int((2 * Rnd()) + 0))
  28.             Loop While ((cards(shown_card) = 1) Or (shown_card = choice))
  29.  
  30.             staywins = staywins + Int(cards(choice))  ' the case where you won by staying with your choice
  31.             Dim temp As Integer
  32.             temp = choice + shown_card
  33.             switchwins = switchwins + Int(cards(2 - (temp)))  ' the case where win by switching
  34.             cards(winner_redcard) = 0 ' reset the winning card for the next round of game
  35.         Next
  36.  
  37.         Debug.Print("Switchwins = ")
  38.         Debug.Print(switchwins)
  39.         Debug.Print("Staywins = ")
  40.         Debug.Print(staywins)
  41.  
  42.     End Sub
  43. End Class