Having a little trouble for my final game project

the game im making is a dice game where you play against 5 computer players. There is 12 rounds and each round you use is 2 dice and the best of that round gets a point.The overall winner of those rounds wins the game. My problem is i cannot figure how to stop a run time error or how to fix it.The next question is that when the scoring of each round sometimes more than one will get a score because there seems to be a tie. Is there any suggestions on how to maybe fix this or maybe just leave it alone. I figured this would happen because since your only rolling two dice and max points you can get is 12 and theirs 5 other computer players
Heres my stuff so far


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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
       #include <iostream>  

	#include <time.h>

	#include <cstdlib>

	#include <windows.h>  

	using namespace std;

	void one();

	void two();

	void three();

	void four();

	void five();

	void six();

	//Declare Functions used

	int main()

	{

	short unsigned int score1 = 0;

	short unsigned int compScore1 = 0;
	short unsigned int compScore2 = 0;
	short unsigned int compScore3 = 0;
	short unsigned int compScore4 = 0;
	short unsigned int compScore5 = 0;

	short unsigned int num1 = 0;
	short unsigned int num2 = 0;

	short unsigned int compNum1 = 0;
	short unsigned int compNum2 = 0;
	short unsigned int compNum3 = 0;
	short unsigned int compNum4 = 0;
	short unsigned int compNum5 = 0;

	short unsigned int sum = 0;

	short unsigned int compSum1 = 0;
	short unsigned int compSum2 = 0;
	short unsigned int compSum3 = 0;
	short unsigned int compSum4 = 0;
	short unsigned int compSum5 = 0;
	char letter;

	//Declare Variables

	srand(time(NULL)); 

	//Initialize random number generator


 	 while (letter != 'x')

	{  
	cout << "Your Score: " << score1 << endl;

	cout << "computer 1 Score: " << compScore1 << endl << endl;

	cout << "computer 2 score:" << compScore2 << endl << endl;

	cout << "computer 3 score:" << compScore3 << endl << endl;

	cout << "computer 4 score:" << compScore4 << endl << endl;

	cout << "computer 5 score:" << compScore5 << endl << endl;

	cout << "Press r to roll or x to quit: ";

	cin >> letter;

	num1 = 1 + rand() % (6 - 1 + 1);

	num2 = 1 + rand() % (6 - 1 + 1);

	compNum1 = 1 + rand() % (6 - 1 + 1);

	compNum2 = 1 + rand() % (6 - 1 + 1);

	compNum3 = 1 + rand() % (6 - 1 + 1);

	compNum4 = 1 + rand() % (6 - 1 + 1);

	compNum5 = 1 + rand() % (6 - 1 + 1);


//Random numbers

 

	sum = num1 + num1;
    
	compSum1 = compNum1 + compNum1;

        compSum2 = compNum2 + compNum2;

	compSum3 = compNum3 + compNum3;

	compSum4 = compNum4 + compNum4;

	compSum5 = compNum5 + compNum5;
 
//Calculate Sums

 

	if (letter == 'x')

	break;

	if (letter != 'r')

{

	system("cls");

	continue;

}

 

	switch (num1,num2)

{

	case 1:

	one();

	break; 

	case 2:

	two();

	break;

	case 3:

	three();

	break;

	case 4:

	four();

	break;

	case 5:

	five();

	break;

	case 6:

	six();

	break;

	default:

	cout << "Error"; 

	break;

} //end switch

 

	switch (num2)




{

	case 1:

	one();

	break;

	case 2:

	two();

	break;

	case 3:

	three();

	break;

	case 4:

	four();

	break;

	case 5:

	five();

	break;

	case 6:

	six();

	break;

	default:

	cout << "Error";

	break;

} //end switch

 

	cout << endl << "Yours: " << num1 << ", " << num2 << endl;

	cout << "Computer 1 " << compNum1 << ", " << compNum1 << "\n\n";

	cout << "Computer 2 " << compNum2 << ", " << compNum2 << "\n\n";

	cout << "computer 3 " << compNum3 << ", " << compNum3 << "\n\n";

	cout << "computer 4 " << compNum4 << ", " << compNum4 << "\n\n";

	cout << "computer 5 " << compNum5 << ", " << compNum5 << "\n\n";




//Display dice and numbers

 

if (sum > compSum1)
{
      compScore1++;
} 
if (sum > compSum2)
{
      compScore2++;
}
if (sum > compSum3)
{
      compScore3++;
}
if (sum> compSum4)
{
     compScore4++; 
}
if (sum > compSum5)
{
    compScore5++;
}
	cout << "DICEY YOU WON" << endl << endl;

score1++;

{



	cout << "WAWAWAWAAAAAAAA You Lost!" << endl << endl;

}

 

//Calculate score

 

system("pause");

system("cls");

 

if (score1 == 12)

{

MessageBox(0, "DICEY YOU WON!", "Results:", MB_ICONEXCLAMATION);

break;

}






if  (compScore1 == 12)
if (compScore2==12)
if (compScore3==12)
if (compScore4==12)
if (compScore5==12)
 
{

MessageBox(0, "WAWAWAAAAAAAAa", "Results:", MB_ICONEXCLAMATION);

break;

}

}

return 0;

}

 

void one()

{
cout << "1" << endl;
}

void two()

{
cout << "2" << endl;
}

void three()

{
cout <<"3" << endl;
}

void four()

{

cout << "4" << endl;

}

void five()

{
cout << "5" << endl;

}

void six()

{
cout << "6" << endl;

}                                                    
Last edited on
Sorry about that Hamsterman i will do this from now on
Sorry, but what you have done is very confused. I'm not sure I understood your requirements, but this might get you started. This isn't how I would really write it, but perhaps it's more clear than something that's "prettier".

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
int main()
{
    const int NUM_PLAYERS = 6;

    // Seed random number generator.
    srand(...);

    for (int rnd = 0; rnd < 12; rnd++)
    {
        // Roll the dice for each player for the round.
        int scores[NUM_PLAYERS];
        for (int player = 0; player < NUM_PLAYERS; player++)
        {
            scores[player] = rollDice();
        }

        // Determine the winner of the round.
        int winner = 0;
        int max_score = 0;
        for (int player = 0; player < NUM_PLAYERS; player++)
        {
           if (scores[player] > max_score)
           {
               winner = player;
               max_score = scores[player]
           }
        }
        wins[winner]++;
    }

    // Determine who won the most rounds.
    int winner = 0;
    int max_wins = 0;
    for (int player = 0; player < NUM_PLAYERS; player++)
    {
       if (wins[player] > max_wins)
       {
           winner = player;
           max_wins = wins[player];
       }
    }
    // You can choose youself to be any of the 6 players.
    if (winner == ME)
        cout << "I won!\n";
}

int rollDice()
{
    // Generate two random numbers between 1 and 6 and return their sum.
}

You should work more on formatting..
Here (your code):
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
#include <iostream>  
#include <time.h>
#include <cstdlib>
#include <windows.h>  
using namespace std;

void one();
void two();
void three();
void four();
void five();
void six();

//Declare Functions used

int main(){
    short unsigned int score1 = 0;

    short unsigned int compScore1 = 0;
    short unsigned int compScore2 = 0;
    short unsigned int compScore3 = 0;
    short unsigned int compScore4 = 0;
    short unsigned int compScore5 = 0;

    short unsigned int num1 = 0;
    short unsigned int num2 = 0;

    short unsigned int compNum1 = 0;
    short unsigned int compNum2 = 0;
    short unsigned int compNum3 = 0;
    short unsigned int compNum4 = 0;
    short unsigned int compNum5 = 0;

    short unsigned int sum = 0;

    short unsigned int compSum1 = 0;
    short unsigned int compSum2 = 0;
    short unsigned int compSum3 = 0;
    short unsigned int compSum4 = 0;
    short unsigned int compSum5 = 0;
    char letter;

    //Declare Variables

    srand(time(NULL)); 

    //Initialize random number generator


    while (letter != 'x'){  
        cout << "Your Score: " << score1 << endl;
        cout << "computer 1 Score: " << compScore1 << endl << endl;
        cout << "computer 2 score:" << compScore2 << endl << endl;
        cout << "computer 3 score:" << compScore3 << endl << endl;
        cout << "computer 4 score:" << compScore4 << endl << endl;
        cout << "computer 5 score:" << compScore5 << endl << endl;
        cout << "Press r to roll or x to quit: ";

        cin >> letter;

        num1 = 1 + rand() % (6 - 1 + 1);
        num2 = 1 + rand() % (6 - 1 + 1);
        compNum1 = 1 + rand() % (6 - 1 + 1);
        compNum2 = 1 + rand() % (6 - 1 + 1);
        compNum3 = 1 + rand() % (6 - 1 + 1);
        compNum4 = 1 + rand() % (6 - 1 + 1);
        compNum5 = 1 + rand() % (6 - 1 + 1);


        //Random numbers

        sum = num1 + num1;
        compSum1 = compNum1 + compNum1;
        compSum2 = compNum2 + compNum2;
        compSum3 = compNum3 + compNum3;
        compSum4 = compNum4 + compNum4;
        compSum5 = compNum5 + compNum5;
	 
        //Calculate Sums

	 

        if (letter == 'x') break;

        if (letter != 'r'){
            system("cls");
            continue;
        }

        switch (num1,num2){
            case 1:
                one();
                break;
            case 2:
                two();
                break;
            case 3:
                three();
                break;
            case 4:
                four();
                break;
            case 5:
                five();
                break;
            case 6:
                six();
                break;
            default:
                cout << "Error";
                break;
        } //end switch
		
        switch (num2){
            case 1:
                one();
                break;
            case 2:
                two();
                break;
            case 3:
                three();
                break;
            case 4:
                four();
                break;
            case 5:
                five();
                break;
            case 6:
                six();
                break;
            default:
                cout << "Error";
                break;
        } //end switch

        cout << endl << "Yours: " << num1 << ", " << num2 << endl;
        cout << "Computer 1 " << compNum1 << ", " << compNum1 << "\n\n";
        cout << "Computer 2 " << compNum2 << ", " << compNum2 << "\n\n";
        cout << "computer 3 " << compNum3 << ", " << compNum3 << "\n\n";
        cout << "computer 4 " << compNum4 << ", " << compNum4 << "\n\n";
        cout << "computer 5 " << compNum5 << ", " << compNum5 << "\n\n";

        //Display dice and numbers

        if (sum > compSum1)
        {
            compScore1++;
        } 
        if (sum > compSum2)
        {
            compScore2++;
        }
        if (sum > compSum3)
        {
            compScore3++;
        }
        if (sum> compSum4)
        {
            compScore4++; 
        }
        if (sum > compSum5)
        {
            compScore5++;
        }
		
        cout << "DICEY YOU WON" << endl << endl;

        score1++;

        {
            cout << "WAWAWAWAAAAAAAA You Lost!" << endl << endl;
        }


        //Calculate score

        system("pause");
        system("cls");

        if (score1 == 12){
            MessageBox(0, "DICEY YOU WON!", "Results:", MB_ICONEXCLAMATION);
            break;
        }

        if (compScore1 == 12)
        if (compScore2==12)
        if (compScore3==12)
        if (compScore4==12)
        if (compScore5==12){
            MessageBox(0, "WAWAWAAAAAAAAa", "Results:", MB_ICONEXCLAMATION);
            break;
        }
    }
    return 0;
}

 

void one(){
    cout << "1" << endl;
}

void two(){
    cout << "2" << endl;
}

void three(){
    cout <<"3" << endl;
}

void four(){
    cout << "4" << endl;
}

void five(){
    cout << "5" << endl;
}

void six(){
    cout << "6" << endl;
} 


I compiled it and got no run time error. It is a bad code though..

line 2 should be ctime.
lines 17-40. lots of repetitions here. you should use arrays here. also, note that while human player has two variables for dice rolls, computer players only have one each.
lines 51-77. again, lots of repetitions. if you used arrays, you could fit write in few lines using a for loop. also, note that sum is the first dice * 2, which makes no sense..
line 90. num1, num2 is not what you think (whatever you think..). it is equivalent to num2.
lines 90-135. firstly, they serve no purpose. there is no need to show those rolls since you're showing them on line 138 anyway. also, the switch is not needed. cout << num1 << " " << num2; would have worked.
lines 147-166. you give your opponents points for rolling less than you? what you should be doing is finding which one rolled the most. again, an array would make this simple.
lines 168, 173. you both win and loose simultaneously.. you really need some conditions here.
lines 187-191. when you put ifs one after another, you get "if condition 1 and condition 2 and ... then". I'm not sure if that was the intention.
lines 201-223. these functions are not needed at all as "cin << number" will do this for you.

good luck.
Topic archived. No new replies allowed.