#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <ctime>
#include <iostream>
#include <time.h>
usingnamespace std;
//Funcation Prototype
int roll(); //Rolls one die
int roll2(); //Rolls two die and adds them together
int readIntPos(string); //Reads in a response from prompt
void setRand(int); //Sets seed to srand or time depending on user input
bool playCraps(int); //Plays one game of craps
int printGameStats(int,int); //Prints game stats
//Main
int main ()
{
int win = 0; //number of wins
int loss = 0; //number of losses
int seed; //seed
bool gameResult; //gameResult is the result of the game of craps played
int numGames = 0; //number of games to be played
//Prompt user for number of games to be played
numGames = readIntPos("Enter the number of games: ");
//Call playCraps
gameResult=playCraps(seed);
for (int x=0; x<numGames; x++) //Calculate number of wins/losses
{
if (gameResult == true) //If true +1 win
win++;
elseif (gameResult == false)
loss++; //If false +1 loss
}
cout << "The number of games played is: " << numGames << endl;
cout << win;
cout << loss;
return 0;
}
//-------------------------------------
//Name: roll
//Purpose: Roll die
//Parameters:
//Returns: interger between 1 and 6
//-------------------------------------
int roll()
{
//Generate number
int die = 0;
die = (rand() % 6 + 1);
return die;
}
//-------------------------------------
//Name: roll
//Purpose: Roll die
//Parameters:
//Returns: interger between 1 and 6
//-------------------------------------
int roll2()
{
//Generate number
int totalRoll = 0;
int die1 = 0;
int die2 = 0;
die1 = roll();
die2 = roll();
totalRoll = die1+ die2;
return totalRoll;
}
//-------------------------------------
//Name: readIntPos
//Purpose: read in a positive integer
//Parameters:
//Returns: interger between 1 and 6
//-------------------------------------
int readIntPos(string prompt)
{
int value = 0;
cout << prompt;
cin >> value;
while ( value <=0 )
{
cout << "Invalid imput - Must be a positive";
cout << endl;
cout << prompt;
cin >> value;
}
return value;
}
//-------------------------------------
//Name: setRand
//Purpose: if seed = 999 then srand time
//Parameters: seed
//Returns:
//-------------------------------------
void setRand(int value)
{
if(value == 999)
{
srand((time(NULL)));
}
else
{
srand(value);
}
}
//-------------------------------------
//Name: playCraps
//Purpose: play a full game of craps
//Parameters:
//Returns: interger between 1 and 6
//-------------------------------------
bool playCraps(int seed)
{
//Variable Declaration
int die = 0;
int totalRoll = 0;
string prompt = "";
int numGames = 0;
int gameNum = 0;
int pointNum = 0;
int value = 0;
bool result;
//Promp user for seed
seed = readIntPos("Enter seed for random number generator (999 to use time): ");
setRand(seed);
pointNum = roll2();
if (pointNum == 7 || pointNum == 11)
{
result = true;
}
elseif (pointNum == 2 || pointNum == 3 || pointNum == 12 )
{
result = false;
}
else
{
die = roll2();
while(die != pointNum and die != 7)
{
die = roll2();
}
if(die == pointNum)
{
result = true;
}
elseif(die == 7)
{
result = false;
}
}
return result;
}
//-------------------------------------
//Name: printGameStats
//Purpose: print game stats
//Parameters: int wins int losses
//Returns: game stats
//-------------------------------------
//printGameStats(int loss, int win)
//{
// percent = ((win/loss)* (100))
//
//
//
//
//
//}