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

• 10-30-2011, 06:40 AM
scd250
Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
Removing my code.
• 10-30-2011, 07:16 AM
pbrockway2
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
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)
• 10-30-2011, 07:22 AM
pbrockway2
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
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.

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.
• 10-30-2011, 08:50 AM
scd250
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
sdfasdfasfasdf
• 10-30-2011, 09:30 AM
scd250
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
asdfasdfasdfasdfasf
• 10-30-2011, 10:18 AM
JosAH
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
• 10-30-2011, 08:53 PM
scd250
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
pbrockway2
Re: Coin toss program. Please *DO NOT* feed me the answer but I DO want help! :)
You are saying count>nFlips in the loop.