Results 1 to 8 of 8
  1. #1
    scd250 is offline Member
    Join Date
    Oct 2011
    Posts
    34
    Rep Power
    0

    Default Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    Removing my code.
    Last edited by scd250; 11-02-2011 at 10:44 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    Java Code:
        // step 2:
        // initialize all of the values in the array to 0
     
    for(int count=MIN_HEADS; count<maxHeads; count++){
          counts[count] = 0;
        }
    Just a little point while I read the code... The condition in that for loop doesn't look right. It's quite possible to get maxHeads heads so that entry in the counts array should also be initialised to zero.

    Eg, suppose the user wanted ten flips per trial. In that case you have to have space to record eleven possible outcomes for a trial: 0,1,2,3,4,5,6,7,8,9,10 heads.

    Also, I'm wondering what happens if you omit step 2. (besides upsetting the teacher)

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    Java Code:
        // step 3:
        // flip the coin for n sets with nFlips flips per set
        // count the number of heads in each set (heads = 1, tails = 0)
     
    for (int s = 0; s < nSets; s++){
        int sum = 0;
        for (int f = 0; f <nFlips; f++){
            sum = sum +(myCoin.flip()? 1:0);
     
        }
    }
    For set s you obtain the number of heads, sum. But shouldn't you do something with sum once you have calculated it? Hint: yes you must, otherwise you have no data to send to the histogram in step 5.

    [Edit]

    Also note that your counts array entries which you made zero, stay zero because you never change them. This explains the problem you started the thread with (the zero probabilities.) ANd it suggests what you might do with sum once you have calculated it.
    Last edited by pbrockway2; 10-30-2011 at 07:30 AM.

  4. #4
    scd250 is offline Member
    Join Date
    Oct 2011
    Posts
    34
    Rep Power
    0

    Default Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    sdfasdfasfasdf
    Last edited by scd250; 11-07-2011 at 08:19 AM.

  5. #5
    scd250 is offline Member
    Join Date
    Oct 2011
    Posts
    34
    Rep Power
    0

    Default Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    asdfasdfasdfasdfasf
    Last edited by scd250; 11-07-2011 at 08:19 AM.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    Read line #5 of your code again; I don't think the loop condition makes sense ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    scd250 is offline Member
    Join Date
    Oct 2011
    Posts
    34
    Rep Power
    0

    Default Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    I can't see it :/

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)

    You are saying count>nFlips in the loop.

Similar Threads

  1. help with my coin toss program please?
    By tran21 in forum New To Java
    Replies: 6
    Last Post: 10-30-2011, 05:20 AM
  2. Trying to finish coin toss project
    By learn in forum New To Java
    Replies: 2
    Last Post: 10-29-2011, 11:54 PM
  3. coin flip program
    By chandrasekhar.melam in forum New To Java
    Replies: 5
    Last Post: 09-26-2011, 05:30 PM
  4. Coin assigning program
    By Jamesing in forum New To Java
    Replies: 10
    Last Post: 03-11-2011, 05:57 AM
  5. coin toss program(Eclipse)
    By ccie007 in forum New To Java
    Replies: 5
    Last Post: 08-06-2010, 07:03 PM

Posting Permissions

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