SHOW:
|
|
- or go back to the newest paste.
| 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); |
| 8 | + | void printDirections(int, int, int[]); |
| 9 | void printBallsInSlots(int, int[]); | |
| 10 | ||
| 11 | int main() | |
| 12 | {
| |
| 13 | int choice[50]; | |
| 14 | int balls = getBalls(); | |
| 15 | int slots = getSlots(); | |
| 16 | ||
| 17 | - | printDirections(balls, slots); |
| 17 | + | printDirections(balls, slots, choice); |
| 18 | printBallsInSlots(slots, choice); | |
| 19 | } | |
| 20 | ||
| 21 | int getBalls() | |
| 22 | {
| |
| 23 | cout << "Enter the amount of balls to drop: "; | |
| 24 | int balls; | |
| 25 | cin >> balls; | |
| 26 | return balls; | |
| 27 | } | |
| 28 | ||
| 29 | int getSlots() | |
| 30 | {
| |
| 31 | cout << "Enter the amount of slots in the bean machine: "; | |
| 32 | int slots; | |
| 33 | - | void printDirections(int balls, int slots) |
| 33 | + | |
| 34 | return slots; | |
| 35 | } | |
| 36 | ||
| 37 | void printDirections(int balls, int slots, int choice[]) | |
| 38 | - | string direction = ""; |
| 38 | + | |
| 39 | srand(time(0)); | |
| 40 | int total = 0; | |
| 41 | string options[] = { "L", "R" };
| |
| 42 | string direction = ""; | |
| 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 | total = total + choice[i]; | |
| 53 | } | |
| 54 | - | cout << "" << endl; |
| 54 | + | |
| 55 | } | |
| 56 | cout << endl; | |
| 57 | - | void printBallsInSlots() |
| 57 | + | |
| 58 | ||
| 59 | void printBallsInSlots(int slots, int choice[]) | |
| 60 | {
| |
| 61 | cout << endl << endl; | |
| 62 | for(int i=0; i < slots; i++){
| |
| 63 | cout << "Slot #" << i << " contains " << choice[i] << " balls." << endl; | |
| 64 | } | |
| 65 | ||
| 66 | } |