Problem with Craps Program

Hey guys been trying to figure out what I'm doing wrong for like an hour. For some reason

For some reason it won't read in Loss at all it will only say that all the games played are all wins.

Any help, advice, or tips are appreciated :)



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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#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>

using namespace 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++;
        else if (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;
            }
            else if (pointNum == 2 || pointNum == 3 || pointNum == 12 )
            {
                result = false;
            }
            else
            {
                die = roll2();
                while(die != pointNum and die != 7)
                    {
                        die = roll2();
                    }
                    if(die == pointNum)
                    {
                        result = true;
                    }
                    else if(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))
//
//
//
//
//
//}

Topic archived. No new replies allowed.