I need help putting together a program that simulates the tossing of 3 die and computes the probability of obtaining each of the values 3 to 18. It should ask the user how many rolls to simulate, and then perform the simulation and report the results. Including an appropriate srand() function so it doesn't compute different results each time.
Here is a function to help you get started it isn't totally complete so make sure you fill in the blank. But that should take care of the roll function that will be called whenever you want to roll the dice.
1 2 3 4 5 6 7 8 9 10 11 12
int rollDice(int &one, int &two, int &three)
{
// Init srand with time for better random numbers
one = rand() // Add something here so it gets the values 1 through whatever you want
two = rand() // Add something here so it gets the values 1 through whatever you want
three = rand() // Add something here so it gets the values 1 through whatever you want
int total = one + two + three;
return total;
}
#include <iostream>
#include <ctime>
usingnamespace std;
int main()
{
srand(time(0));
int num1 = rand() % 6 + 1;
int num2 = rand() % 6 + 1;
int num3 = rand() % 6 + 1;
int sum = num1 + num2 + num3;
cout<<"The first roll was: "<<num1<<endl;
cout<<"The second roll was: "<<num2<<endl;
cout<<"The third roll was: "<<num3<<endl;
cout<<"The total was: "<<sum<<endl;
}