I need to create a roll dice program that allows the user to both input a desired sum and the number of times they want the dice to be rolled. I can get the first part but I cant get it the part where you enter a number of rolls.
int num, rollDice(int num);
int main()
{
cout << "Enter the desired sum of the two die" << endl;
cin >> num;
cout<< "The number of tries to get the desired 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;
}
int num, rollDice(int num);
int main()
{
int num, sum;
cout << "Enter the desired sum of the two die" << endl;
cin >> sum;
cout << "Enter the number rolls you want" << endl;
cin >> num;
cout<< "The number of tries to get the desired 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;
}
I was wondering whether the loop where the dice were rolled should be executed a fixed number of times (like a for-loop) or maybe set an upper limit on how many repetitions. Not sure what to suggest right now.