Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <string>
- using namespace std;
- int getBalls();
- int getSlots();
- void printDirections(int, int, int[]);
- void printBallsInSlots(int, int[]);
- int main()
- {
- int choice[50];
- int balls = getBalls();
- int slots = getSlots();
- printDirections(balls, slots, choice);
- printBallsInSlots(slots, choice);
- }
- int getBalls()
- {
- cout << "Enter the amount of balls to drop: ";
- int balls;
- cin >> balls;
- return balls;
- }
- int getSlots()
- {
- cout << "Enter the amount of slots in the bean machine: ";
- int slots;
- cin >> slots;
- return slots;
- }
- void printDirections(int balls, int slots, int choice[])
- {
- srand(time(0));
- int total = 0;
- string options[] = { "L", "R" };
- string direction = "";
- for (int j = 0; j < balls; j++)
- {
- direction = "";
- for (int i = 1; i < slots; i++)
- {
- choice[i] = rand() % 2;
- direction = direction + options[choice[i]];
- total = total + choice[i];
- }
- cout << direction << endl;
- }
- cout << endl;
- }
- void printBallsInSlots(int slots, int choice[])
- {
- cout << endl << endl;
- for(int i=0; i < slots; i++){
- cout << "Slot #" << i << " contains " << choice[i] << " balls." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement