Does anyone have rolling two dice code for me looking at it?
Printable View
Does anyone have rolling two dice code for me looking at it?
Umm, you're talking about 2 lines of code. Look at the Rnd function.
You're so helpful, Machaira. Maybe we should give you a reward.
Take a look at this, VBHelp2003:
VB Code:
'make sure you add a CommandButton first Private Sub Command1_Click() Randomize MsgBox "You rolled a " & Int(Rnd * 6) + 1 & "!" End Sub
As far as I can tell, he posted all you need to know. Posting code is akin to cheating on a test. You learn nothing.Quote:
Originally posted by The Hobo
You're so helpful, Machaira. Maybe we should give you a reward.
Z.
thank hobo, so if I want sum of rolling two dice, I just add
sum = roll1 + roll2 ?
Zaei! tests are not easy kind of this questions.
So there's no possible way to examine the code and learn from it?Quote:
Originally posted by Zaei
As far as I can tell, he posted all you need to know. Posting code is akin to cheating on a test. You learn nothing.
Z.
He asked for code to look at. I gave it to him. Sue me.
How much do you think I can get. :DQuote:
Originally posted by The Hobo
Sue me.
hey,
have u gotten a check yet for spedia.com... as in...does it actually work or has it worked for u??
Asking questions instead of providing answers is a much more effective teaching tool. Provide new avenues to explore, instead of simply pointing out a single one.Quote:
Originally posted by The Hobo
So there's no possible way to examine the code and learn from it?
He asked for code to look at. I gave it to him. Sue me.
Z.
Thanks for providing your opinion.Quote:
Originally posted by Zaei
Asking questions instead of providing answers is a much more effective teaching tool. Provide new avenues to explore, instead of simply pointing out a single one.
Nope, No check, But that is just because I have never qualified for one. But aperantly (yes I have actually studied these guys out) They are one of the only companys that does pay, This is due to the fact that They have advanced Cheat detecting motives. But they are supposed to be Legitamite.Quote:
Originally posted by CrazedWombat
hey,
have u gotten a check yet for spedia.com... as in...does it actually work or has it worked for u??
You're welcome.Quote:
Originally posted by The Hobo
Thanks for providing your opinion.
Z.
So if he had asked for the code for a craps game would you have given it to him? Where do you draw the line? Will you continue to give him the code he needs since he's never going to learn how to research his problems to find the answers he needs? If he had taken the information I gave him, it would have taken him under 30 seconds to find the answer to his question.Quote:
Originally posted by The Hobo
He asked for code to look at. I gave it to him. Sue me.
I spend hours on various boards helping people and it's not hard to tell the difference between people that have tried to find the answer themself and are posting as a last resort and people that don't want to even attempt to find the answer, and just want the solution handed to them.
You're not doing the latter type person any favors by just giving the code to them.
It was a dice snippet. Like you said, two lines. I'm not going to give full application code. It's a matter of extremes.Quote:
Originally posted by Machaira
So if he had asked for the code for a craps game would you have given it to him? Where do you draw the line?
While we're being so exact (and not exaggerative), you have no way of knowing that it'd take him under 30 seconds. For all we know he can have a 14.4 modem and would take him 2 minutes just to load a simple webpage.Quote:
Originally posted by Machaira
Will you continue to give him the code he needs since he's never going to learn how to research his problems to find the answers he needs? If he had taken the information I gave him, it would have taken him under 30 seconds to find the answer to his question.
1) Get a life, and 2) realize that you can't predict everybody. Maybe this was his last resort. Maybe he doesn't speak much English and simply doesn't know how to effectively search.Quote:
Originally posted by Machaira
I spend hours on various boards helping people and it's not hard to tell the difference between people that have tried to find the answer themself and are posting as a last resort and people that don't want to even attempt to find the answer, and just want the solution handed to them.
Yes I am. I'm answering his question. That's not a favor? And don't tell me he needs to learn it on his own. He can learn it by looking at the code. It's not that complicated.Quote:
Originally posted by Machaira
You're not doing the latter type person any favors by just giving the code to them.
Not everyone learns the same way, either. Some people need visuals, some people need to read, some people need examples.
So go cry me a river, buttercup. I'll answer questions the way I see fit, regardless of whether or not you like it.
hey
hobo is right, the only way i ever learned/learn is through examples, if i hadnt known that code i would be grateful, and if u spend hours on here helping people out, is ur previous reply the only help u give them? vague objectives...?? what if it was something much more complicated? would u have said look in a book? remember that u were a noob once too and however long ago that was, u didnt even know what random meant. so be kool and spend ur hours with more information than present, and Hobo, your way is best.
*Estimate the probabilities of obtaining 2 through 12 when rolling two dice and summing the face values by simulation. The experiment should be performend N (input variable) times.
My output come out
2
3
4
5
6
7
8
9
10
11
12
Option Explicit
Dim x As Integer
Dim sum As Integer
Dim roll1 As Integer
Dim roll2 As Integer
Dim freq(2 To 12) As Integer
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdRoll_Click()
Call Randomize
roll1 = 1 + Int(Rnd() * 6)
roll2 = 1 + Int(Rnd() * 6)
sum = roll1 + roll2
freq(sum) = freq(sum) + 1
For x = LBound(freq) To UBound(freq)
lstList1.AddItem x & vbTab & freq(x) & vbTab & vbTab & Format$(freq(x) + freq(sum))
Next x
End Sub
*Estimate the probabilities of obtaining 2 through 12 when rolling two dice and summing the face values by simulation. The experiment should be performend N (input variable) times.
My output come out:
2 0 1
3 0 1
4 0 1
5 0 1
6 0 1
7 1 2
8 0 1
9 0 1
10 0 1
11 0 1
12 0 1
Can someone help me about this output? thank
Option Explicit
Dim x As Integer
Dim sum As Integer
Dim roll1 As Integer
Dim roll2 As Integer
Dim freq(2 To 12) As Integer
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdRoll_Click()
Call Randomize
roll1 = 1 + Int(Rnd() * 6)
roll2 = 1 + Int(Rnd() * 6)
sum = roll1 + roll2
freq(sum) = freq(sum) + 1
For x = LBound(freq) To UBound(freq)
lstList1.AddItem x & vbTab & freq(x) & vbTab & vbTab & Format$(freq(x) + freq(sum))
Next x
End Sub
Make your listbox wider...
THe code works fine, though Im sure it would be annoying to have to repeatedly click the cmdRoll button....
Z.
My listbox is fine.
But the output must be
after rolling two dice, for example 4 3
it suppose be 7 right? because 4 + 3 = 7 (sum)
sum is a global variable. It will immediatly add whatever the last roll was to the third column, which makes no sense.
Also, You are going to run into problems when rolling... 1 + int(rnd() * 6) returns in a range 1..7.
Z.
[edit]
See what I mean about posting code?
Err, actually it will add the number of "sum"s that have been rolled previously.
Z.