Hi,
I don't know what your problem is but I will make some observations anyway.
My initial problem was that I had read in a maths book that the average
no. of 6 heads in a row in a sequence of 200 tosses was at least one...
my program kept providing 0.77
I have since realised that they must have meant "at least 6"...
First of all, get rid of the global variables. There is no need to resort
to global variables in a program this small and simple.
I only started learning programming a few months ago- so I'm not sure
what the problem is with global variables? (And what's an alternative?)
Is there any reason not to use enum instead of the #defines? They are more
appropriate and would probably do what you want.
The #defines seem to do what I want - enums might be more appropriate,
but I haven't yet learnt what they are
Don't use the sentinel. Sentinels are something you resort to when there is
a good reason. There is no good reason here.
The sentinel seemed easy enough to use - what potential problems are
there with using them? Why are they only a last resort?
Reduce the program to its essence. You seem to be able to handle command
line, a default set of data, or user supplied data. This is just
obfuscating things right now. Choose one. I would use built in data for
initial testing.
The command line data is just for the seed, so I can manually assess
the degree of probability accuracy ... the default data is probably
unnecessary.
Pay attention to the definition of in_a_row. Does it mean *exactly* n in a
row? The code says no. To determine that your code would have to look at
the next character - the one that breaks the sequence- , and it doesn't do
that. To me, exactly is the most sensible thing to compute. For example,
if in_a_row is 3 what does the following sequence of heads get counted as:
001111111100 ?
It does compute 'exactly x in a row' ... which is what I intended...
(it looks at the character that breaks the sequence when 'i' is
incremented - which breaks the while loop)
while(A
==H)
{
i++;
row_h++;
}
if(row_h==in_a_row)
count++;
row_h=0;
I tried the corner cases, in a row = 1 and in a row = 0 and got strange
results.
You might refuse to accept such questions as n = 1 in the final version of
your code.
I'd like to be able to test for n=1 ... so I'll keep trying
If n=0, I could just assign the number of tosses to n, and test for
that instead.
Too complicated.
Note that if the number drawn is less than 1/2 RAND_MAX, you have divided
the distribution into two almost equal parts.
My uni textbook says "If you need your program to be portable, and
require the values to be uncorelated even when compiled with the
original rand and srand functions, you should extract the desired value
from high-order bits rather than low-order ones..."
What are those parens for? Just a kind of idle question.
I'm a newbie ... by habbit I tend to stick in as many extra parens as
possible
(I realise now they are reduntant).