Laboratory activity 3 b1

726 views
653 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
726
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Laboratory activity 3 b1

  1. 1. 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 Function End Class

×