You are supposed to count the number of rolls it takes to get boxcars, not the number of boxcars you get in N rolls. So for each trial you are going to roll the dice as many times as it takes to get boxcars. Then you move on to the next trial. Your looping would look something like this:
So, instead of a single number count, make count an array with the definition
count(1) = the number of times it took only one roll to get boxcars
count(2) = the number of times it took two rolls to get boxcars
count(3) = the number of times it took three rolls to get boxcars
etc.
Suppose you use a variable called rolls inside your loop to keep track of the number of rolls it takes to get boxcars for that particular trial, then inside your loop you would at some point have this line when you finally get the boxcars:
count(rolls) = count(rolls) + 1;
Rolling the dice over and over again would probably be best with a while-loop. E.g.,
while( true )
if( test to see if you got boxcars here )
end
end
Does this outline make sense to you? Then after the for-loop you would just do this:
Best Answer