justinpuckett

Untitled

May 27th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 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[50];
  31.     int total[50];
  32.     int count = 0;
  33.  
  34.     for (int i = 1; i < (slots * balls) + 1; i++)
  35.     {
  36.         choice[i] = rand() % 2;
  37.  
  38.  
  39.         direction = direction + options[choice[i]];
  40.         if (i % (slots) == 0)
  41.         {
  42.             cout << direction << endl;
  43.             direction = "";
  44.         }
  45.  
  46.  
  47.         count = count + choice[i];
  48.         if (i % (slots) == 0)
  49.         {
  50.             total[(i / slots) - 1] = count;
  51.             count = 0;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment