### HELP! - Bell Curve Simulator

The program simulates a ball going through a pyramid of pins, and calculates which slot it ultimately ends up in. As balls accumulate in the respective slots, a bell curve will be formed.

Input: Levels (how many rows of pins are there. Allow up to 100 and Balls (how many balls will be dropped into the machine)
Output: How many of the balls dropped ended up in each of the slots at the bottom. (The number of slots will be one more than the number of levels)

One ball will be dropped at a time. When a ball is dropped, it will first hit the middle pin on level 1, and then randomly bounce left or right to the next level of pins and so on. For every level the amount of pins increases. Level 1 has 1 pin, and level 2 has 2 pins, etc.

I'm assigning each ball at the start a value, and then for each level randomly add 1 or subtract 1 from that value, simulating left (negative) or right (positive). The resulting value will then determine the slot. What is this starting value? Is it different if there are an even or odd number of slots?

Once all the balls have been “dropped”, output the number of balls in each slot. I will also be outputting a graph of the results represented by "*". I'll need a scaling factor to do this so the bell curve also looks about the same size.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970`` `````` #include #include #include #include #include using namespace std; int main() { int levels[99], balls, slots, count[100], num, ball; slots = 0; cout<<"Bell Curve Simulator"<>levels[99]; cout<<"Enter # of balls: "; cin>>balls; for (int i = 0; i < 99; i++) { i = count[100]; slots = levels[99] + 1; } while (balls > 0) { balls--; if (slots % 2==0) { ball = slots/2 + 1; } else { ball = (slots + 1)/2 + 1; } num = rand() % 2; if (num = 0) { ball--; } if (num = 1) { ball++; } if (ball = slots) { count[slots]++; } } cout<<"Slot #"<
Topic archived. No new replies allowed.