The purpose of this program is to determine a typical random die roll of n dice with m sides. Right now I'm not finished with that. I plan to the likelyhood of it occurring in an array. For example if there's 3 ways to roll a three then in the array there would be 3 3's. Once I get the values stored into an array I plan on using a random integer to call a value from that array. But it doesn't work. It seems like it skips over the input into the array because it outputs random crap instead of what should be in the array.
#include <iostream>
#include <math.h>
usingnamespace std;
//factorial function
short fact(short n)
{
if(n==0) return 1;
if (n>0) return n*fact(n-1);
}
//ncr function
short NCR(short n, short k)
{
short num ;
num = fact(n)/(fact(k)*fact(n-k));
return num;
}
//probability function that determines the frequency of a rolled number
short probability(short dice_num, short dice_side,short number)
{
short sum=0;
for(short i=0; floor((number-dice_num)/(dice_side))>i; i++)
{
sum+= pow(-1,i)*NCR(dice_num,i)*NCR((number-dice_side*i-1),(dice_num-1));
}
return sum;
}
int main()
{
short dice_num,dice_side;
cout<< "dice sides";
cin >> dice_side;
cout<< "number of dice";
cin >> dice_num;
short y=0;
short all_values[1000];
for (short i = dice_num ; (dice_num*dice_side - dice_num) > i;i++)
{
short sum=probability(dice_num,dice_side,i);
for (short x;sum > x; x++)
{
// I think the problem is here but idk why
all_values[y]=i;
y++;
}
}
short result;
for (short i; i>y ; i++)
{
if (all_values!=0)
{
result = all_values[i];
cout<<result;
}
}
return 0;
}