% Filename: ProbHeadFlip.m
% M-file to compute probability of flipping a head
% when you repeat 1000 coin flips 10000 times
%
% n = Number of times to collect output
n = 10000;

% Initialize heads count
Hcount = 0;

% Run coinflips n times
for i = 1:n
   % Coinflips will run 1000 experiments each time 
   output = coinflips(1000);
   
   % sum up number of heads outputs
   Hcount = Hcount + output(1,1);
end
   
% Compute average number of heads
Haverage = Hcount/1000;

% Estimate probability of flipping heads
ProbH = Haverage/n;

% Print out answer
fprintf('P(Heads) = %6.4f\n',ProbH);
