Great, you've got some code, and what exactly is your question?
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
You have forgotten to use the return value of flip(). If you did this
if (flip()==1) . I think you would be a lot better than looking at your loop count varible.
If really helps lots to run you code on paper, with a list of variables when the code is small and you are beginning. They you would see why you only get one head.
It also helps to printout the results every turn.
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138
First seed your rand function.
srand(time(0));
The this code :
for (int toss = 0; toss < coinToss; toss++)
{
flip();
if (toss == 1)
heads++;
else
tails++;
}
is wrong.
You need to assign the value return to a variable and then use it to compare.
for(int i = 0; i < 100; i++)
{
int side = flip();
if(side == 0) tails++;
else heads++;
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
also you are starting the variable heads at one which will throw off you answer. you should initialize both heads and tails as 0.
NathanOliver
Veteran Poster
1,084 posts since Apr 2009
Reputation Points: 215
Solved Threads: 189