Need help with a roll dice program

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.



#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

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;
}
the user to both input a desired sum and the number of times they want the dice to be rolled

Then you will need a variable to store each of these values, such as
1
2
int sum; // desired sum
int num; // number of times to roll dice 

For each of these, use cout to prompt the user and cin to get the value.

At the moment, you only have one cin, you need two.
I have this now, but it doesn't change anything


#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

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'm not sure I understand the rules of the game. What is supposed to happen?
Allow the user to enter the desired sum of the numbers to be rolled as well as allow the user to call the rollDice function as many times as desired
allow the user to call the rollDice function as many times as desired

Here I'm not sure what is supposed to happen. The program calls the rollDice() function just once. Are you saying it should be called more than once?
I'm not sure, I just copied what the textbook says for the problem, it's worded really confusingly
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.
I think I need to give the user an option to play again somehow, but i'm not really sure how to go about it
Topic archived. No new replies allowed.