laboratory activity 3 b1
TRANSCRIPT
Laboratory Activity 3 (Batch 1)
Coin Toss Problem
Write a windows application program that stimulates coin tossing. Let the program toss the coin each time the user presses the Toss Button. Count the number of times each side of the coin appears. Display the results. The program should call a separate method Flip(), with no arguments and return True for Heads, and False for Tails.
Public Class Form1 Public HeadCount As Integer = 0 Public TailCount As Integer = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Flip() Then HeadCount = HeadCount + 1 Label1.Text = "Heads: " & HeadCount Else TailCount = TailCount + 1 Label2.Text = "Tails: " & TailCount
End If
End Sub
Function Flip() As Boolean Dim objRandomNumber As Random = New Random
Dim randomNumber As Integer
randomNumber = objRandomNumber.Next(1, 3)
If randomNumber = 1 Then Return True Else Return False
End If
End FunctionEnd Class