function cdf = beta_binomial_cdf ( x, a, b, c )

%*****************************************************************************80
%
%% BETA_BINOMIAL_CDF evaluates the Beta Binomial CDF.
%
%  Discussion:
%
%    A simple summing approach is used.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    09 October 2004
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer X, the argument of the CDF.
%
%    Input, real A, B, parameters of the PDF.
%    0.0 < A,
%    0.0 < B.
%
%    Input, integer C, a parameter of the PDF.
%    0 <= C.
%
%    Output, real CDF, the value of the CDF.
%
  if ( x < 0 )

    cdf = 0.0;

  elseif ( x < c )

    cdf = 0.0;
    for y = 0 : x
      pdf = r8_beta ( a + y, b + c - y ) / ( ( c + 1 ) ...
        * r8_beta ( y + 1,  c - y + 1 ) * r8_beta ( a, b ) );
      cdf = cdf + pdf;
    end

  elseif ( c <= x )

    cdf = 1.0;

  end

  return
end
