Results 1 to 8 of 8
- 10-30-2011, 06:40 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 34
- Rep Power
- 0
- 10-30-2011, 07:16 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
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.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; }
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)
- 10-30-2011, 07:22 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
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.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); } }
[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.
- 10-30-2011, 08:50 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 34
- Rep Power
- 0
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.
- 10-30-2011, 09:30 AM #5
Member
- Join Date
- Oct 2011
- Posts
- 34
- Rep Power
- 0
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.
- 10-30-2011, 10:18 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-30-2011, 08:53 PM #7
Member
- Join Date
- Oct 2011
- Posts
- 34
- Rep Power
- 0
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
I can't see it :/
- 10-31-2011, 01:05 AM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Similar Threads
-
help with my coin toss program please?
By tran21 in forum New To JavaReplies: 6Last Post: 10-30-2011, 05:20 AM -
Trying to finish coin toss project
By learn in forum New To JavaReplies: 2Last Post: 10-29-2011, 11:54 PM -
coin flip program
By chandrasekhar.melam in forum New To JavaReplies: 5Last Post: 09-26-2011, 05:30 PM -
Coin assigning program
By Jamesing in forum New To JavaReplies: 10Last Post: 03-11-2011, 05:57 AM -
coin toss program(Eclipse)
By ccie007 in forum New To JavaReplies: 5Last Post: 08-06-2010, 07:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks