I think it would be more efficient to access the ResultsArray directly by using the produced value as the index.
const int MAX_VALUE = 18; int results[MAX_VALUE + 1] = {0}; //add 1 to compensate for zero-based arrays for (int i = 0; i < MAX_ITERATIONS; ++i) { dieSet.roll() results[dieSet.getResult()]++; }
Thanks man. I worked on it over the weekend, and I've made progress. It compiles and runs. Now, how do I take the results and place them into a vertical and a horizontal histogram of the data?
Die.h
#ifndef DIE_H // allows for additional
#define DIE_H
class Die
{
public: // available outside of class
Die(); // SMF to set value
void Roll(); // member functions
int GetFaces();
private: // not available outside class
int Face;
};
#endif
Die.cpp
#include "Die.h" // for processing die face
#include <cstdlib> // for the library rand() function
Die::Die() //Initializes Face data member
{
Face = 1;
}
void Die::Roll()
{
Face = rand() % 6 + 1;
}
int Die::GetFaces()
{
return Face;
}
DieRoll.h
#ifndef DIEROLL_H // allows for additional
#define DIEROLL_H
#include "Die.h"
class DiceRoll // classs that specifies a collection of 3 contained Die objects
{
public:
void RollDice(); // Calls Roll() function on each contained die
int GetRollFaces(); // Returns the sum of the current Face value of Die1, Die2, & Die3
private:
Die Die1; // The three die contained in this -i.e
Die Die2; // objects of this class automatically contain
Die Die3; …