srand() function help

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.

What have you written so far?
I have no idea. This isn't like a homework assignment. I am just trying to find out how I would write such a program. Thanks
Seems like homework to me. Have you even started C++?
Yes, I started it in college but never really learned anything.
closed account (3qX21hU5)
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;
}
How does this look

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <ctime>
using namespace 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;

 }
Topic archived. No new replies allowed.