//===================================================== file = diceSim2.c ===== //= Simulation of rolling dice and getting a pair = //============================================================================= //= Notes: = //= 1) This program is for assignment #2 for CAP 4800 (Simulation) for = //= Summer 2013. This is an example of a Monte Carlo simulation. = //= 2) See NUM_ROLL and TRACE in the #define section = //= 3) Ignore two warnings on always false and unreachable code = //=---------------------------------------------------------------------------= //= Build: bcc32 diceSim2.c, cl diceSim2.c, gcc diceSim2.c -o diceSim = //=---------------------------------------------------------------------------= //= Execute: diceSim2 = //=---------------------------------------------------------------------------= //= Sample execution: = //= = //= >>> The simulation is running... = //= ============================================================= = //= == *** Simulation of rolling dice and getting a pair *** == = //= ============================================================= = //= = MODEL INPUT: = //= = Number of dice rolls = 10000000 = //= ============================================================= = //= = MODEL OUTPUT: = //= = Percent pairs = 16.661420 % = //= ============================================================= = //=---------------------------------------------------------------------------= //= History: KJC (05/21/13) - Genesis (from diceSim2.c from 2011) = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for rand() //----- Constants ------------------------------------------------------------- #define FALSE 0 // Boolean false #define TRUE 1 // Boolean true #define NUM_ROLL 10000000 // Number of iterations to simulate #define TRACE FALSE // Enable or disable trace //===== Main program ========================================================== void main(void) { int redDie; // Value of red die (1, 2, ..., 6) int blueDie; // Value of blue die (1, 2, ..., 6) int pairCount; // Count of event redDie == blueDie int i; // Loop counter // Output a "running" banner printf(">>> The simulation is running... \n"); // Run the simulation for NUM_ROLL dice rolls pairCount = 0; for (i=0; i