All pastes #75241 Raw Edit

die rolling - ooble

public text v1 · immutable
#75241 ·published 2006-06-29 23:21 UTC
rendered paste body
void cmd_roll()
{
   // Find the two numbers on either side of "d".
    if (prompt_arguments.size() <= 1)
    {
        cout << endl <<"Please enter the dice to roll... ex: 1d4";
        prompt();
    }
    else
    {
        string die1;
        string die2;
        int result = 0;
        stringstream convert;
        int numtoroll = 0;

        string full = prompt_arguments[1];
        int dpos = full.find("d");
        full.replace(dpos, 1, " ");
        int spacepos = full.find(" ");
        die1 = full[0];
        die2 = full[2];
        convert << die1;
        convert >> numtoroll;
        // Begin Dice Rolling
        // Seed random number generator with time.

        if (die2 == "4")
        {
            for (int i = 0; i < numtoroll; i++)
            {
                result = result + (rand() % 4) + 1;
            }
        }
        if (die2 == "6")
        {
            for (int i = 0; i < numtoroll; i++)
            {
                result = result = (rand() % 6) + 1;
            }
        }


        cout << endl << "Rolled " << die1 << "d" << die2 << ": " << result;
    }
}