function insurance_simulation_test2 ( )

%*****************************************************************************80
%
%% insurance_simulation_test2() simulates one case many times.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 February 2024
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'insurance_simulation_test2()\n' );
  fprintf ( 1, '  Average many instances of a single case.\n' );

  age = 25;
  term = 40;
  yearly_fee = 500.0;
  death_benefit = 100000.0;

  pay_in_total = 0.0;
  pay_out_total = 0.0;
  value_total = 0.0;
  death_total = 0;

  trials = 1000;
  verbose = false;

  for i = 1 : trials
    [ pay_in, pay_out, pay_age, value ] = insurance_simulation ( ...
      age, term, yearly_fee, death_benefit, verbose );
    pay_in_total = pay_in_total + pay_in;
    pay_out_total = pay_out_total + pay_out;
    value_total = value_total + value;
    if ( 0 < pay_out )
      death_total = death_total + 1;
    end
  end

  pay_in_mean = pay_in_total / trials;
  pay_out_mean = pay_out_total / trials;
  value_mean = value_total / trials;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The case was simulated %d times.\n', trials );
  fprintf ( 1, '  Number of (covered) deaths %d\n', death_total );
  fprintf ( 1, '  Average customer payments  = %g\n', pay_in_mean );
  fprintf ( 1, '  Average company payments   = %g\n', pay_out_mean );
  fprintf ( 1, '  Average bank account value = %g\n', value );

  return
end

