justinpuckett

Untitled

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