//Date: July 24 2016
//Programmer: ********* *****
//Program name: rollDice
//User enters the desired sum of two dice, and the computer generates random numbers until //they equal the desired sum.
#include <iostream> //allows program to input & output
#include <ctime> //contains functions used to work with time
#include <cstdlib> //defines general purpose functions
using namespace std; //program uses standard libraries
unsigned int rollDice(); //function to roll the dice
unsigned int num; //Number input by user (Desired sum of the dice)
unsigned int sum; //The sum of the two dice
unsigned int die1; //Stores the value of the first die
unsigned int die2; //Stores the value of the first die
int rollCount = 0; //Number of times the dice were rolled to achieve the desired sum
srand( static_cast<unsigned int>(time(0))); //Seeds srand() with the time, measured in seconds since the Linux epoch.
int main() //function main
{//begin main
do{ //begin do... while
cout<<"Enter the desired sum of the dice "; //prompts the user for input
cin>> num; //assign the input data to sum
} //end do... while
while (num < 2 || num > 12); //checks to see if the entered integer is an appropriate value for sum
cout << "Invalid number - try again"; //if no, prompt user for input
cin >> num;
while (sum != num){
rollDice(); //Rolls the dice
}//end do... while
return 0; //returns function main
}//end main
unsigned int rollDice()
{//begin function rollDice
unsigned int die1 = 1 + rand() % 6; //roll the first die
unsigned int die2 = 1 + rand() % 6; //roll the second die
rollCount ++; //Increment rollcount
unsigned int sum = die1 + die2; //the sum of the dice
cout << "Player rolled " << die1 << " + " << die2 << " = " << sum << endl; //display the individual values of the dice, and their sum
cout << "The number of times the dice were rolled is " << rollCount << endl; //Display rollCount