Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- int path(int);
- void printHistogram(int[],int, int);
- int main()
- {
- //Number of balls; Number of slots
- int NOB;
- int NOS;
- const int size = 50;
- int slots[size];
- memset(slots, 0, sizeof(slots));
- cout << "Enter the number of slots in the bean machine: ";
- cin >> NOS;
- cout << "Enter the number of balls to drop: ";
- cin >> NOB;
- for (int i = 0; i < NOB; i++)
- {
- slots[path(NOS)]++;
- }
- printHistogram(slots, NOS, NOB);
- return 0;
- }
- int path(const int NOS)
- {
- int P = 0;
- for (int i = 1; i < NOS; i++)
- {
- int direction = rand() % 2;
- if (direction == 1)
- {
- cout << "R";
- }
- else
- {
- cout << "L";
- P++;
- }
- }
- cout << endl;
- return P;
- }
- void printHistofram(int slots[],const int NOS, int NOB)
- {
- char ball[NOS + 1];
- int maxSH = 0;
- for (int i = NOB; i > 0; i--)
- {
- for (int j = 0; j <= NOS; j++)
- {
- if (i == slots[j])
- {
- ball[j] = 'O';
- slots[j]--;
- }
- else
- ball[j] = ' ';
- cout << ball[j];
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement