/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*  Problem chapter4_13                                               */
/*                                                                    */
/*  This program simulates tossing an "unfair" coin.                  */
/*  The user enters the number of tosses.                             */

#include <stdio.h>
 
#define  HEADS  10
#define  TAILS  1
#define  WEIGHT 6
int main(void)
{
   /*  Declare variables and function prototypes.  */
   int tosses=0, heads=0, required=0;
   int rand_int(int a, int b);

   /*  Prompt user for number of tosses.  */
   printf("\n\nEnter number of unfair coin tosses: ");
   scanf("%i",&required);

   /*  Toss coin the required number of times, and  */
   /*  keep track of the number of heads.           */
   while (tosses < required)
   {
	tosses++;
	if (rand_int(TAILS,HEADS) <= WEIGHT)
	   heads++;
   }


   /*  Print results.  */
   printf("\n\nNumber of tosses:     %i\n",tosses);
   printf("Number of heads:      %i\n",heads);
   printf("Number of tails:      %i\n",tosses-heads);
   printf("Percentage of heads:  %f\n", 100.0 * heads/tosses);
   printf("Percentage of tails:  %f\n", 100.0 * (tosses-heads)/tosses);

   /*  Exit program.  */
   return 0;
}

