Determining probability for a variable number of results?

From: April (aprilo_at_highland.net)
Date: 02/21/04

  • Next message: Chris \( Val \): "Re: [C++] Help Parsing an Integer/Character Mix"
    Date: Sat, 21 Feb 2004 08:33:51 -0500
    
    

    What I'm trying to do is create the data for a distribution curve of
    outcomes given x number of 6 sided dice. I can produce the total number of
    outcomes easily enough, but I am having a problem in determining the number
    of individual values. Below is what I have so far.

    #include <iostream>
    #include <vector>
    #include <algorithm>

    #define ROLLS 3
    #define SIDES 6

    typedef unsigned long ulong;
    typedef unsigned short ushort;

    using namespace std;

    int main()
    {
        static ulong outcomes = 1; // total possible outcomes
        const ushort loRange = ROLLS; // lowest possible result
        const ushort hiRange = SIDES*ROLLS; // highest possible result
        const ushort values = (hiRange-loRange)+1; // range lowest to
    highest
        vector<ushort> results; // store all possible outcomes

        for(int i=0; i<ROLLS; i++) // determine total possible
    outcomes
            outcomes *= SIDES;

        results.resize(outcomes*sizeof(ushort)); // pre-set size of vector

        // Rest of code should go here to determine the sum for each possible
        // dice roll producing reults in the range loRange-hiRange
        // then count the number of times that result is produced and finally
        // to divide that count by outcomes to get the probability of that
    result.

        return 0;
    }

    How would I go about filling the vector with the proper values. I can solve
    it for the above values by nesting three for loops, one for each die roll,
    but this doesn't help for an unknown number of die rolls. In the actual
    program I would like the user to supply the number of rolls as well as the
    number of sides on the die, either by command line options or via windows
    controls.

    Thanks for your help,

    April


  • Next message: Chris \( Val \): "Re: [C++] Help Parsing an Integer/Character Mix"