//====================================================== file = coinSim.c ===== //= Simulation of flipping a coin = //============================================================================= //= Notes: = //= 1) This program is a class example for CAP 4800 (Simulation) for = //= Summer 2013. This is an example of a Monte Carlo simulation. = //= 2) See NUM_FLIP and TRACE in the #define section = //= 3) Ignore two warnings on always false and unreachable code = //=---------------------------------------------------------------------------= //= Build: bcc32 coinSim.c, cl coinSim.c, gcc coinSim.c -o coinSim = //=---------------------------------------------------------------------------= //= Execute: coinSim = //=---------------------------------------------------------------------------= //= Sample execution: = //= = //=---------------------------------------------------------------------------= //= History: KJC (05/20/13) - Genesis = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for rand() //----- Constants ------------------------------------------------------------- #define FALSE 0 // Boolean false #define TRUE 1 // Boolean true #define HEAD 0 // Define head as a 0 #define TAIL 1 // Define tail as a 1 #define NUM_FLIP 1000000 // Number of iterations to simulate #define TRACE FALSE // Enable or disable trace //===== Main program ========================================================== void main(void) { int coinFace; // Value of coin face (HEAD or TAIL) int headCount; // Count of event head occurring int i; // Loop counter // Output a "running" banner printf(">>> The simulation is running... \n"); // Run the simulation for NUM_FLIP coin flips headCount = 0; for (i=0; i