-
October 19th, 2012, 12:13 PM
#1
Basic Visual Basic Homework help!!
I am very new to visual basic. My homework assignment is to make a form functional that my teacher set up. The for is a coin toss program that has a text box for heads and tails that will be filled with the head and tails count (the amount it lands on either) The percentage of times it lands on either and the longest run that a head or tail is consecutively landed on. We have a text box the user inserts the amount of flips they want. there are two buttons; one of them just flips the coin as many times as the user inserts and the other button flips the coin until the consecutive flips of either heads or tails is reached from the user inserted amount. I have no clue what to do with the code. How do I do this?!
-
October 19th, 2012, 12:31 PM
#2
Re: Basic Visual Basic Homework help!!
Probably need to GO TO CLASS to learn how NOT to cheat...
-
October 19th, 2012, 12:50 PM
#3
Re: Basic Visual Basic Homework help!!
I have gone to class every single day. The teacher just learned Visual Basic this summer and is not much help. There is no text for this book so I am trying to get HELP any way I can. I am not trying to cheat (although I understand it may seem like that and maybe it even is cheating) I am just really lost and seeing if anyone can give me a hand. I have been working on this problem for a week straight.
-
October 19th, 2012, 01:30 PM
#4
Re: Basic Visual Basic Homework help!!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rnd As New Random
Dim num As Integer
Dim headcount As Double
Dim tailcount As Double
Dim target As Double
For i = 0 To target
num = rnd.Next(0, 2)
headcount = 0
tailcount = 0
If num = 1 Then
headcount += (headcount + 1)
Else
tailcount += (tailcount + 1)
End If
Next
txtHeadsCount.Text = headcount
txtTailsCount.Text = tailcount
This is a code I have so far and all I can do is get it to give me 1 count in either heads or tail at a click
-
October 19th, 2012, 07:46 PM
#5
Re: Basic Visual Basic Homework help!!
Study the RND function, it will help you to simulate the result of each coin flip
http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
October 19th, 2012, 11:55 PM
#6
Re: Basic Visual Basic Homework help!!
Looks a lot like VB.Net, not VB6. Make sure which book you are reading!
This part in particular
Code:
num = rnd.Next(0, 2)
-
October 20th, 2012, 01:33 AM
#7
Re: Basic Visual Basic Homework help!!
For a start, I think you need to make your tailcount and headcount variables Static
-
October 20th, 2012, 01:27 PM
#8
Re: Basic Visual Basic Homework help!!
And this doesn't do what you expect:
Code:
headcount += (headcount + 1)
Headcount = 2
headcount += (headcount + 1)
2 ________ + ( 2+1)
= 5 instead of 3
This will add 1 each time...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|