#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstdlib>
#include <cmath>
using namespace std;
const int NUMBER_GAMES = 10000;
int dice1 = 1 + rand() % 6; // 1st dice roll
int dice2 = 1 + rand() % 6; // 2nd dice roll
int dice3 = 1 + rand() % 6; // 3rd dice roll
int dice4 = 1 + rand() % 6; // 4th dice roll
int main()
{
//variables
int numberWins = 0;
int numberLosses = 0;
int point = 0;
int dice1, dice2, dice3, dice4;
int roll = dice1 + dice2;
int sum = roll; // compute sum of die values
int newRoll = dice3 + dice4;
// conditions of the game
for (int roll = 1; roll <= 10000; roll++)
cout << "Start the roll: \n";
sum = roll;
if ((dice1 + dice2) == 7 || ( dice1 + dice2) == 11)
{
numberWins = numberWins + 1;
cout << "You won !" << endl;
}
if ((dice1 + dice2) == 2 || ( dice1 + dice2) == 3|| ( dice1 + dice2) == 12)
{
numberLosses = numberLosses +1;
cout << "You lose !" << endl;
}
// Establish the Point
else if((dice1 + dice2) == 4 || ( dice1 + dice2) == 5|| ( dice1 + dice2) == 6 || ( dice1 + dice2) == 8||( dice1 + dice2) == 9 ||( dice1 + dice2) == 10)
{
roll = point;
cout << "This is your point" <<endl;
do
{
newRoll = dice3 + dice4;
}
while (newRoll != 7 && newRoll != point);
if ( newRoll == 7)
{
numberLosses = numberLosses +1;
cout << "You did not make your point. You lost" <<endl;
}
else if ( newRoll == point)
{
numberWins = numberWins + 1;
cout << "You made your point. You win" <<endl;
}
}
return 0;
}
int probability ()
{
double winningPercentage;
int numberWins;
winningPercentage = numberWins/NUMBER_GAMES;
system("pause");
return 0;
}
This post has been edited by JackOfAllTrades: 11 October 2010 - 07:16 AM
Reason for edit:: Fixed code tags.

New Topic/Question
Reply



MultiQuote



|