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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;

int main()
{


int levels[99], balls, slots, count[100], num, ball;

slots = 0;


cout<<"Bell Curve Simulator"<<endl;
cout<<"********************"<<endl<<endl;

cout<<"Enter # of levels (1-100): ";
cin>>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 #"<<slots<<"\t"<<endl;
cout<<count[slots]<<"\t"<<endl;


return 0;
}
Topic archived. No new replies allowed.