frogwalk.cc From Astrachan, pp 311 ----------------------------------- #include #include "dice.h" #include "prompt.h" // simulate one-dimensional random walk // Owen Astrachan, 8/13/94 int main() { int numSteps = PromptRange("enter # of steps",0,1000000); int position = 0; // "frog" starts at position 0 Dice die(2); // used for "coin flipping" int k; for(k=0; k < numSteps; k++) { switch (die.Roll()) { case 1: position += 1; // step to the right break; case 2: position -= 1; // step to the left break; } } cout << "final position = " << position << endl; return 0; }