-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
72 lines (61 loc) · 1.29 KB
/
Copy pathmain.cpp
File metadata and controls
72 lines (61 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Made by Darclander :D
* Latest update 2020-04-07
*/
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include "human.h"
void printAll(Human *arr) {
int arr2[10];
for (int i = 0; i < 10; i++) {
arr2[i] = arr[i].print();
}
std::sort(arr2, arr2+10);
for (int i = 0; i < 10; i++) {
std::cout << i+1 << ": " << arr2[i] << "\n";
}
}
int decAll(Human *arr) {
int canGive = 0;
for (int i = 0; i < 10; i++) {
if(arr[i].print()>0) {
arr[i].decDollar();
canGive += 1;
}
}
return canGive;
}
/**
* Increases a random persons stack with 1 as long as there
* are enough dollars left to give
*/
void incRand(Human *arr, int canGive) {
srand(time(NULL));
int random;
while(canGive > 0) {
random = (rand() % 10 + 1) - 1;
arr[random].incDollar();
canGive -= 1;
}
}
int main () {
Human arr [10];
// Total amount of cycles
int x = 1000;
for (int i = 0; i < 10; i++ ) {
arr[i] = *new Human();
}
int canGive = 0;
while(x > 0) {
canGive = decAll(arr);
incRand(arr, canGive);
printAll(arr);
x--;
}
// Cleanup
for(int i = 0; i < 10; i++) {
delete &arr[i];
}
}