Advertisement
Donald_Fortier

Untitled

May 27th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <ctime>
  3. #include <string>
  4. using namespace std;
  5.      
  6. int getBalls();
  7. int getSlots();
  8. void printDirections(int, int);
  9.      
  10. int main()
  11. {
  12.         int balls = getBalls();
  13.         int slots = getSlots();
  14.  
  15.         cout << endl;
  16.      
  17.         printDirections(balls, slots);
  18. }
  19.  
  20. int getBalls()
  21. {
  22.     cout << "Enter the amount of balls to drop: ";
  23.     int balls;
  24.     cin >> balls;
  25.     return balls;
  26. }
  27.  
  28. int getSlots()
  29. {
  30.     cout << "Enter the amount of slots in the bean machine: ";
  31.     int slots;
  32.     cin >> slots;
  33.     return slots;
  34. }
  35.  
  36. void printDirections(int balls, int slots)
  37. {
  38.         srand(time(0));
  39.      
  40.         string options[] = { "L", "R" };
  41.         string direction = "";
  42.         int choice[100];
  43.            
  44.         for (int j = 0; j < balls; j++)
  45.         {
  46.                 direction = "";
  47.      
  48.                 for (int i = 1; i < slots; i++)
  49.                 {
  50.                         choice[i] = rand() % 2;
  51.                         direction = direction + options[choice[i]];
  52.                 }
  53.                 cout << direction << endl;
  54.         }
  55.         cout << "" << endl;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement