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. string Direction(int);
  9. void printOutcomes(int, string);
  10.  
  11. void main()
  12. {
  13.     int balls = getBalls();
  14.     int slots = getSlots();
  15.  
  16.     cout << endl;
  17.  
  18.     string direction = Direction(slots);
  19.     printOutcomes(balls, direction);
  20. }
  21.  
  22. void printOutcomes(int balls, string direction)
  23. {
  24.     for (int j = 0; j < balls; j++)
  25.     {
  26.         cout << direction << endl;
  27.     }
  28.     cout << "" << endl;
  29. }
  30.  
  31. int getBalls()
  32. {
  33.     cout << "Enter the amount of balls to drop: ";
  34.     int balls;
  35.     cin >> balls;
  36.     return balls;
  37. }
  38.  
  39. int getSlots()
  40. {
  41.     cout << "Enter the amount of slots in the bean machine: ";
  42.     int slots;
  43.     cin >> slots;
  44.     return slots;
  45. }
  46.  
  47. string Direction(int slots)
  48. {
  49.     srand(time(0));
  50.     int choice[100];
  51.     string options[] = { "L", "R" };
  52.     string direction = "";
  53.    
  54.     for (int i = 1; i < slots; i++)
  55.     {
  56.         choice[i] = rand() % 2;
  57.         direction = direction + options[choice[i]];
  58.     }
  59.     return direction;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement