Roll Dice Program

Hi, I'm currently working on a dice program in which I'm to create a function (called rollDice) that rolls a pair of dice until the sum of the numbers rolled is a specific number(given by user), and entered as the desired sum of the numbers to be rolled. The program must print the number of times the dice are rolled to get the desired sum and it must print the value of die1 and die2.

After looking at similar programs in my textbook, I came up with this code but it's still missing a lot things such as I still need to get my program to properly print out the number of times the dice were rolled, and to print out the value of die1 and die2.

I do know that I must include some parameters because the max sum of 2 dice is 12. So I've came up with this code but I don't know where to include it.
do
{
Cout << "enter the desired sum: " << endl;
cin>>num;
}

while (num < 2)|| num>12);

Any help is greatly appreciated, thanks.


#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int num, rollDice(int num);
int main()
{
cout << “ Enter the number you want the two dice to equal: “;
cin >> num;
cout<< “The number of times the dice are rolled to get the sum” << num << “ = “ <<
rollDice(num) << endl;
return 0;
}
int rollDice(int num)
{
int die1;
int die2;
int sum;
int rollCount = 0;
srand(time(0));


do
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
rollCount++;
}
while (sum != num);
return rollCount;
}
Hi,
int num, rollDice(int num);

Should be :
1
2
int num;
int rollDice(int num);
http://www.cplusplus.com/forum/beginner/194554/
TheIdeasMan wrote:
Just a note for the future :+)

There also shouldn't be 2 topics about essentially the same subject. There is a risk that the same things will be said in both, possibly making it a time waster for those who reply.
Topic archived. No new replies allowed.