My objective in this program was to write a function that rolls a pair of dice until the sum of the numbers rolled is a specific number(given by the user). It is also suppose to display the number of times the dice are rolled to get the desired sum. If everything looks ok, How do I allow the user to call the rollDice function as many times as they want?
#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;
}
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace 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;
}