Odds of 100000 games of craps

Hello all. Really at my wits end with this. I made a craps game and that was fine. On top of it I was supposed to then make something that could give me the odds of winning or losing if I ran it 100000 times. Here's what I have. It compiles, but the odds arent right as they should be near 50 according to my professor. (It goes from 30 - 70 to 200- 0)

, thank you much :)/

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
  include<iostream>
using namespace std;

int main()
{
  srand(time(0));

  int firstpt;
  int otherroll;
  float win=0.0;
  float lose=0.0;
  float count=0.0;
  float percentw;
  float percentl;


  firstpt = (rand()%6+1) + (rand()%6 +1);


  for( ; count<= 100000; count = count + 1.0)
    {

if(firstpt == 7 || firstpt == 11)
  {
  // cout<<firstpt<<" Is a winner!";                                                                                                                        
  win++;
  }

    else if (firstpt == 2 || firstpt == 3 || firstpt == 12)
      {
      // cout<<firstpt<<" Is a Loser!";                                                                                                                     
      lose++;
      }

      else

do
  {
    otherroll = (rand()%6+1) + (rand()%6+1);
 // cout << otherroll << endl;                                                                                                                                                                           
  }

 while (otherroll != 7 && otherroll != firstpt);

  if (otherroll == 7)
    { // cout<<" is a loser";                                                                                                                                                                               
    lose++;
    }

  else
    {  // cout<<" is a winner.";                                                                                                                                                                            
    win++;
    }
}


  percentw = (win / 100000)  *100;
    percentl = (lose/100000) *100;

    cout<<percentw<<endl;
    cout<<percentl;

return 0;

}
Last edited on
Topic archived. No new replies allowed.