demo-nested-loops-xmas-lights-short - / / / / / / / /...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// Programmer: Doug Hogan // Program: An extra demo of a simulation using nested loops. // Date: 11/7/2008 // Description: This program simulates multiple strands of Christmas lights. // of "one light goes out, they all go out" fashion. // We are looking for how many bulbs we need to check before // finding the faulty bulb. // (Short form without analysis of results.) #include <iostream> // for cin, cout, endl #include <cstdlib> // for random number generator #include <ctime> // for time method so we can seed the generator using namespace std; const int NUM_LIGHTS_PER_STRAND = 100; // how many bulbs are in a strand of lights const int NUM_STRANDS = 250; // how many strands of lights // (250 is the "Christmas Vacation" setting :)) const double PROB_FAILURE = 0.05; // probability an individual bulb fails const int ERROR_VALUE = -1; // value used to indicate that in an individual // trial, a burned out bulb was not found bool DoesBulbFail() // PRE: Random number generator rand() has been seeded
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

demo-nested-loops-xmas-lights-short - / / / / / / / /...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online