Results 1 to 21 of 21

Thread: hi

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7

    hi

    Does anyone have rolling two dice code for me looking at it?

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Umm, you're talking about 2 lines of code. Look at the Rnd function.

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You're so helpful, Machaira. Maybe we should give you a reward.

    Take a look at this, VBHelp2003:

    VB Code:
    1. 'make sure you add a CommandButton first
    2. Private Sub Command1_Click()
    3.   Randomize
    4.   MsgBox "You rolled a " & Int(Rnd * 6) + 1 & "!"
    5. End Sub
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by The Hobo
    You're so helpful, Machaira. Maybe we should give you a reward.
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7
    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.

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Lively Member
    Join Date
    May 2001
    Posts
    96
    Originally posted by The Hobo
    Sue me.
    How much do you think I can get.

  8. #8
    Member CrazedWombat's Avatar
    Join Date
    Oct 2002
    Location
    asylum
    Posts
    47
    hey,
    have u gotten a check yet for spedia.com... as in...does it actually work or has it worked for u??
    Wombat

    "I like to go to the schoolyard where i can watch the little kids jumping and screaming....but they dont know im using blanks"

    "Before you set yourself on fire, remember to take off your shoes... nothing smells worse than burning rubber."

    "They advertise that certain laundry detergents can take blood stains out of clothes, i say that if you have blood stains on your clothes, maybe your laundry is the least of your worries."

    Sometimes when I'm driving around I see a sign that says, CAUTION: SMALL CHILDREN PLAYING. I slow down, and then it occurs to me: I'm not afraid of small children.

    "My programs dont have bugs, they have random features" - MisianThrop

    "The good thing about our ticket to the future is that it's always blank" - Trigun

  9. #9
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.
    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.

    Z.

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    Thanks for providing your opinion.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Lively Member
    Join Date
    May 2001
    Posts
    96
    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??
    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.

  12. #12
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by The Hobo
    Thanks for providing your opinion.
    You're welcome.

    Z.

  13. #13
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Originally posted by The Hobo
    He asked for code to look at. I gave it to him. Sue me.
    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.

    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.

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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?
    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.

    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.
    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.

    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.
    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.

    Originally posted by Machaira
    You're not doing the latter type person any favors by just giving the code 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.

    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    Member CrazedWombat's Avatar
    Join Date
    Oct 2002
    Location
    asylum
    Posts
    47
    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.
    Wombat

    "I like to go to the schoolyard where i can watch the little kids jumping and screaming....but they dont know im using blanks"

    "Before you set yourself on fire, remember to take off your shoes... nothing smells worse than burning rubber."

    "They advertise that certain laundry detergents can take blood stains out of clothes, i say that if you have blood stains on your clothes, maybe your laundry is the least of your worries."

    Sometimes when I'm driving around I see a sign that says, CAUTION: SMALL CHILDREN PLAYING. I slow down, and then it occurs to me: I'm not afraid of small children.

    "My programs dont have bugs, they have random features" - MisianThrop

    "The good thing about our ticket to the future is that it's always blank" - Trigun

  16. #16

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7

    Unhappy

    *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

  17. #17

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7

    Unhappy

    *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

  18. #18
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Make your listbox wider...

    THe code works fine, though Im sure it would be annoying to have to repeatedly click the cmdRoll button....

    Z.

  19. #19

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7
    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)

  20. #20
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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?

  21. #21
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Err, actually it will add the number of "sum"s that have been rolled previously.

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width