42 lines
884 B
C
42 lines
884 B
C
|
#include <stdio.h> // printf
|
||
|
#include <stdlib.h> // rand and srand
|
||
|
#include <time.h> // time
|
||
|
|
||
|
int roll_dice(int Sides)
|
||
|
{
|
||
|
return (rand()%Sides)+1;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
// Init:
|
||
|
int FirstDice = 20;
|
||
|
int SeccondDice = 8;
|
||
|
|
||
|
srand(time(0));
|
||
|
|
||
|
int Average = 0;
|
||
|
int Distribution[11]; //TODO: Set the right size. TIP: save the array size in a variable for later use
|
||
|
|
||
|
// TODO: set all values of Distribution to zero using a for-loop
|
||
|
|
||
|
// Calculate Distribution and Average
|
||
|
for (int i = 0; i < 100000; i++)
|
||
|
{
|
||
|
int Value = roll_dice(FirstDice)+roll_dice(SeccondDice);
|
||
|
|
||
|
// TODO: count up the frequency of the Value.
|
||
|
// The smallest possible value 2 is supposed to be counted in index 0
|
||
|
|
||
|
Average = Average + Value;
|
||
|
}
|
||
|
Average = Average/100000;
|
||
|
|
||
|
// Output code:
|
||
|
// TODO: adjust this to the array size
|
||
|
for(int i = 0; i < 6; i++)
|
||
|
{
|
||
|
printf("%d %d\n", i+2, Distribution[i]);
|
||
|
}
|
||
|
}
|