Counting using switch statement

I eventually want the output to count the number of win and loses for the amount of rolls it took

like 400 wins 500 loses with one roll
234 wins 434 loses with two rolls
...
I am wondering why my switch statement is not keeping count of gameWonOne, gameWonTwo, etc.
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

//initalize the function
int diceToss();

int main()
{
    int numberOfRolls = 0;
    int totalNumberOfRolls =0;
    int gameNumber = 0;
    int rolledNumber = 0;
    int pointNumber = 0;
    int possibleRollsLeft =0;
    int SIZE = 0;
    int ROLLS =0;
    double chanceOfWinning = 0;
    int numberGamesWon = 0;
    int numberGameslose = 0;
    enum statusOfGame {WIN , LOSE, CONTINUE};
    int gameHasBeenWon = 0;
    int gameHasBeenLost = 0;
    enum statusOfGame status;
    srand(time(0));
    
    //listing to store output in number games won in x rolls
    int gameWonOne =0;
    int gameWonTwo =0;
    int gameWonThree=0;
    int gameWonFour=0;
    int gameWonFive=0;
    int gameWonSix=0;
    int gameWonSeven=0;
    int gameWonEight=0;
    int gameWonNine =0;
    int gameWonTen =0;
    int gameWonEleven=0;
    int gameWonTwelve=0;
    int gameWonThirteen=0;
    int gameWonFourteen=0;
    int gameWonFifteen=0;
    int gameWonSixteen=0;
    int gameWonSevenTeen=0;
    int gameWonEighteen=0;
    int gameWonNinteen=0;
    int gameWonTwenty=0;
    int gameWonTwentyOne=0;
    int gameWontTwentyTwo=0;
    int gameWonTwentyThree=0;
    int gameWontTwentyFour=0;
    int gameWontTwentyFive=0;
    int gameWonTwentySix=0;
    int gameWonTwentySeven=0;
    int gameWonTwentyEight =0;
    int gameWontTwentyNine=0;
    int gameWonThirty=0;
    
    //listing to store output in number games lost in x rolls
    int gameLoseOne =0;
    int gameLoseTwo =0;
    int gameLoseThree=0;
    int gameLoseFour=0;
    int gameLoseFive=0;
    int gameLoseSix=0;
    int gameLoseSeven=0;
    int gameLoseEight=0;
    int gameLoseNine =0;
    int gameLoseTen =0;
    int gameLoseEleven=0;
    int gameLoseTwelve=0;
    int gameLoseThirteen=0;
    int gameLoseFourteen=0;
    int gameLoseFifteen=0;
    int gameLoseSixteen=0;
    int gameLoseSevenTeen=0;
    int gameLoseEighteen=0;
    int gameLoseNinteen=0;
    int gameLoseTwenty=0;
    int gameLoseTwentyOne=0;
    int gameLosetTwentyTwo=0;
    int gameLoseTwentyThree=0;
    int gameLosetTwentyFour=0;
    int gameLosetTwentyFive=0;
    int gameLoseTwentySix=0;
    int gameLoseTwentySeven=0;
    int gameLoseTwentyEight =0;
    int gameLosetTwentyNine=0;
    int gameLoseThirty=0;

    //setting precision for output to 2 decimal places
    cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
    
    for( totalNumberOfRolls=1; totalNumberOfRolls < 5501; totalNumberOfRolls++)
    {
        rolledNumber = diceToss();
        // win by rolling a 7 or 11 on first roll
        if (rolledNumber == 7 || rolledNumber == 11)
        {
            status = WIN;
            gameHasBeenLost++;
            numberOfRolls = 1;
        }
        // lose by rolling a 2, 3, or 12
        else if (rolledNumber == 2 || rolledNumber == 3 | rolledNumber == 12)
        {
            status = LOSE;
            gameHasBeenLost++;
            numberOfRolls = 1;
        }
        // else need to roll the point before rolling a 7
        else
            numberOfRolls = 1;
        {
            pointNumber = rolledNumber;
            do
            {
                //roll new number to compare to point
                rolledNumber = diceToss();
                if(rolledNumber == pointNumber)
                {
                    status = WIN;
                    gameHasBeenWon++;
                    numberOfRolls++;
                }
                else if (rolledNumber == 7)
                {
                    status = LOSE;
                    gameHasBeenLost++;
                    numberOfRolls++;
                }
                else
                    status = CONTINUE;
                numberOfRolls++;
                //redo process
            }
            //keep user in loop until either wins or loses
            while (rolledNumber != pointNumber && rolledNumber != 7);
        }
        switch (numberOfRolls)
        {
            case '1':
                if (rolledNumber == pointNumber)
                {
                    gameWonOne++;
                }
                    
                else
                {
                    gameLoseOne++;
                }
                break;
            case '2':
                if (rolledNumber == pointNumber)
                {
                    gameWonTwo++;
                }
                else
                {
                    gameLoseTwo++;
                }
                break;
            case '3':
                if (rolledNumber == pointNumber)
                {
                    gameWonThree++;
                }
                else
                {
                    gameLoseThree++;
                }
                break;
            case '4':
                if (rolledNumber == pointNumber)
                {
                    gameWonFour++;
                }
                else{
                    gameLoseFour++;
                }
                break;
            case '5':
                if (rolledNumber == pointNumber)
                {
                    gameWonFive++;
                }
                else{
                    gameLoseFive++;
                }
                break;
            case '6':
                if (rolledNumber == pointNumber)
                {
                    gameWonSix++;
                }
                else
                {
                    gameLoseSix++;
                }
                
            case '7':
                
            case '8':
                
            case '9':
                
            case '10':
                
            case '11':
                
            case '12':
                
            case '13':
                
            case '14':
                
            case '15':
                
            case '16':
                
            case '17':
                
            case '18':
                
            case '19':
                
            case '20':
                
            case '21':
                
            case '22':
                
            case '23':
                
            case '24':
                
            case '25':
                
            case '26':
                
            case '27':
                
            case '28':
                
            case '29':
                
            case '30':
                return 0;
        }
        
        
        totalNumberOfRolls = totalNumberOfRolls + numberOfRolls;

        cout << gameHasBeenWon << " games won and " << gameHasBeenLost << " games lost on roll " << numberOfRolls << endl;
    }
    chanceOfWinning = ((double)gameHasBeenWon/(gameHasBeenWon + gameHasBeenLost));
    cout << "The chances of winning are " <<   " = " << chanceOfWinning << endl;
    double averageGame = 0;
    
    cout << "The average game length is " << averageGame << " rolls." << endl;
    cout << "Press any key to continue..." << endl;
    return 0;
Have you considered arrays/vectors?
1
2
3
4
5
6
7
8
9
10
11
12
//create two vectors 1 for wins 1 for losses
//set the size of the vectors to 30
//set default value of each element to 0
std::vector<int> gameWon( 30 , 0 ) , gameLost( 30 , 0 );
int rolls = 1; //example roll could be what ever from your game
if( rolledNumber == pointNumber)
{
    //increment the wins for that roll by 1
    ++gameWon[ rolls - 1 ]; //vectors start at index 0
} else {
    --gameLost[ rolls - 1 ]; //decremented by 1 on loss
}


On another side note you may want to reconsider how you write your for loops. yeah for( totalNumberOfRolls=1; totalNumberOfRolls < 5501; totalNumberOfRolls++)
works.... but you should use the standard for loop
for (variable = 0; variable < amount; ++variable ) {
so for yours it would be
for( totalNumberOfRolls = 0; totalNumberOfRolls < 5500; ++totalNumberOfRolls ){
most people also use i or it for their value. Being an int or an iterator.
Last edited on
int gameWonOne =0;
int gameWonTwo =0;
int gameWonThree=0;
int gameWonFour=0;
int gameWonFive=0;
int gameWonSix=0;
int gameWonSeven=0;
int gameWonEight=0;
int gameWonNine =0;
int gameWonTen =0;
int gameWonEleven=0;
int gameWonTwelve=0;
int gameWonThirteen=0;
int gameWonFourteen=0;
int gameWonFifteen=0;
int gameWonSixteen=0;
int gameWonSevenTeen=0;
int gameWonEighteen=0;
int gameWonNinteen=0;
int gameWonTwenty=0;
int gameWonTwentyOne=0;
int gameWontTwentyTwo=0;
int gameWonTwentyThree=0;
int gameWontTwentyFour=0;
int gameWontTwentyFive=0;
int gameWonTwentySix=0;
int gameWonTwentySeven=0;
int gameWonTwentyEight =0;
int gameWontTwentyNine=0;
int gameWonThirty=0;


This is why god made arrays just so you know. And I think the problem is that dicetoss() has no implementation so there's nothing to keep track of. Didn't read beyond that in your code so fix it and will reply if you have more problems.
Topic archived. No new replies allowed.