#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int rollDice(int num);
int ask_to_roll_dice(int sum);
int main(int argc, constchar * argv[])
{
int sum;
bool quit = false;
do {
sum = ask_to_roll_dice(sum);
cout << "The number of times the dice are rolled to " << "get the sum " << sum <<" = " << rollDice(sum) << endl;
char input = '\0';
cout << "Would you like to roll again? " << endl;
cin >> input;
switch (input) {
case N:
quit = true;
break;
case Y:
quit = false;
break;
default:
cout << "Invalid input";
}
} while (!quit);
return 0;
}
int ask_to_roll_dice(int sum){
cout << "What sum do you want to obtain by rolling the dice? ";
cin >> sum;
cout << endl;
return sum;
}
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;
}