Craps Simulator

In this program... i am attempting to display odds at 100,1000,10000... the problem that i am having is... calculations are not right.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70


#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main(){   //open main
	double winFirst = 0;
	double looseFirst = 0;  
	double winGame = 0;
	double looseGame = 0;
	double dice1;
	double dice2;
	double diceSum;
	double numGames =0;
	double point;
	int i;
	
	cout<< setw(40) <<"Craps Simuation" << endl;
	cout<< setw(60) <<"Number of games in simulation: xxxxx"<< endl;
	
	cout<< setw(30)<< "Actual" << setw(20) << "Simulated" << setw(20)<< "%Difference"<< endl;
	cout<< endl;
	cout<< "win on first roll" << setw(11) <<".223"<<setw(20)<< winGame <<endl;
	cout<< "loose on first roll" << setw(10) <<".112"<<setw(30) <<diceSum<< endl;
	cout<< "Total Win" << setw(20) <<".497"<< setw(15)<<looseGame <<endl;
	cout<< "Total loss" << setw(20) <<".503"<<setw(10)<< dice1<<setw(20)<<dice2<<endl;
	cout << endl<< endl;
	
	srand( static_cast<unsigned>(time( 0 )));
	
	
for(i=0; numGames <= 10000; i=i*10){	
	for(i=0; i < numGames; i++){
		dice1 = rand() % 6 + 1;
		dice2 = rand() % 6 + 1;
		diceSum = dice1 + dice2;
		
		if(diceSum == 7 || diceSum == 11){
			winFirst++;
			winGame++;
		}	
		else if(diceSum == 2,3,12){
			looseFirst++;
			looseGame++;
		}	
		else{
			point=diceSum;
		}
		do{
			dice1 = rand() % 6 + 1;
			dice2 = rand() % 6 + 1;
			diceSum = dice1 + dice2;
		}while(diceSum = point || 7);	
		
		if(diceSum == point){
			winGame++;
		}	
		if (diceSum == 7){
			looseGame++;
		}	
	}	
}	
	return 0;
}	
	
	
	

One problem I see, is you are using the variable i, for two different for loops, at the same time. Doesn't work.
1
2
for(i=0; numGames <= 10000; i=i*10){	
	for(i=0; i < numGames; i++){


Plus, you can't use for(i=0; numGames <= 10000; i=i*10) even if you had a different variable. It should be more like for(x=1; x<=numGames; x=x*10) Since you had started i as 0, it would never increase. 0 times 10, is still 0

And lastly, I see else if(diceSum == 2,3,12) That should be more to the order of else if(diceSum == 2 || diceSum == 3 || diceSum == 12)

Hope this helps a bit.
Last edited on
Topic archived. No new replies allowed.