I have a program where I roll a die X number of times and need to print how many times it lands on each side. I tried to create an array in the class aDie that increments each time the corresponding number is rolled but when I go to call and print it in the main my out put is 0. I just picked how many times it landed on the side 4 just to see if it works and it doesn't.
class aDie {
public:
int roll();
int count(int face);
aDie();
private:
int numRolled;
int countOfRoll[6];
};
aDie::aDie() {
int countOfRoll[5] = {0};
}
int aDie::roll() {
numRolled = (rand() % 6) + 1; //gets random number between 1 and 6
countOfRoll[numRolled]++; //increments element numRolled
return numRolled;
}
int aDie::count(int face) {
return countOfRoll[face];
}
int main() {
srand(time(NULL));
//srand(2);
int maxRolls = 10;
vector<int> totalRolls(maxRolls);
int i = 0;
aDie getRan;
for (i = 0; i < maxRolls; ++i) { // iterates loop maxRolls times
getRan.roll(); // gets random number
totalRolls.at(i) = getRan.roll();
cout << totalRolls.at(i) << endl;
}
getRan.count(4);
cout << " test " << getRan.count(4) << endl;