Dice Game Problem

Hello. I have been designing a dice game program that calls for a playet to roll seven dice, each of which results in a value 1 through 6.
The scoring should be that:
-A triple (any 3 or more dice with identical values) scores 100 times the face value
except for three ones which score as 1,000 points.

-If two triples are scored, the score will be 150 times the face value of each,
except for three ones which score as 900 points.

then if no triple is rolled, then each “1" scores 100 points and/or each "5" scores 50 points.

-The game ends when one player scores 10,000 or more points. However, all players should
be able to complete the last turn, and therefore more than one player could score over 10,000 points. The player with the highest score wins. If more than one player matches high
score, it is a tie.


This is what i came up with Im not sure how to apply the scoring method at the end of seven runs. Your input is greatly 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
#include <time.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int dice1, dice2 = 0;
 
void RollDice(); // The Void Program That Rolls The Dice
 
int main()
 {
 srand(time(0));
 int input = 1;
 
do
 {
 if (input == 1)
 {
 system ("Pause");
 RollDice(); // Function That Does Everything For The Code
 
 cout << " Press 1 to Roll and  2 to Quit :";
 }
 
else if (input !=1 || input != 2)
 {
 cout << "Input Again:"<<endl;

 }

 cin >> input;

 }

 while(input!=2);
 
return 1;
 }
 
void RollDice()
 {
 dice1 = (rand()%6+1); // 1-6 Numbers

 dice2 = (rand()%6+1); // To Make It Different It Multiplies By 13
 switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1
 {
 case 1:
 cout <<"player 1"<<endl; 
 cout <<endl;     
 cout << "[ . ] " <<endl;
  break;
 
case 2:
 cout <<"player 1"<<endl; 
 cout <<endl;
 cout << "[ : ]" <<endl;
 break;

case 3:
 cout <<"player 1"<<endl; 
 cout <<endl;
 cout << "[. :]" <<endl;
 break;
 
case 4:
 cout <<"player 1"<<endl;
 cout <<endl;     
 cout << "[: :]" <<endl;
 break;
 
case 5:
 cout <<"player 1"<<endl; 
 cout <<endl;    
 cout << "[:.:]"<<endl;
 break;

 case 6:
 cout <<"player 1"<<endl; 
 cout <<endl;     
 cout << "[:::]" <<endl;
 break;
 
 }

switch(dice2) //Same As Above Except For Dice 2
 {
 case 1:
 cout <<"Player 2" <<endl;
 cout <<endl;
 cout << "[ . ]" <<endl;
 break; 

 case 2:
 cout <<"Player 2" <<endl;
 cout <<endl;
 cout << "[ : ]" <<endl;
 break;

 case 3:
 cout <<"Player 2" <<endl;
 cout <<endl;
 cout << "[. :]" <<endl;
 break;

 case 4:
 cout <<"Player 2" <<endl;
 cout <<endl;
 cout << "[: :]" <<endl;
 break;

 case 5:
 cout <<"Player 2" <<endl;
 cout <<endl;
 cout << "[:.:]" <<endl;
 break;

 case 6:
 cout <<"Player 2" <<endl;
 cout <<endl;
 cout << "[:::]" <<endl;
 break;

 }
 
 } 
Last edited on
Put your code in a code tag. It formats it and makes it readable. It's the <> button on the right side of the text box.
ok there it is
Also use proper indentation. It makes reading long stuff like your big do while loop at the top much easier. Also you could make your output player switch cases at the bottom a single while loop like so
cout << "PLayer " << counter << endl;

that'll get rid of a good 40 lines. also you can put all your couts on one line
Im not sure what you mean. Is it that i should start the cout << "PLayer " << counter << endl; at the beginning of the do statement?
No. What I mean is that you have two very long pieces of similar code, so you should always try and wrap them together to make it easier to read. Something like this:
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
int counter = 1
while(counter <= 2)
{
	switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1
	{
		case 1:
		cout <<"player "<< counter << endl << endl << "[ . ] " << endl;
		break;
	
		case 2:
		cout <<"player "<< counter << endl << endl << "[ : ] " << endl;
		break;
		
		case 3:
		cout <<"player "<< counter << endl << endl << "[. :] " << endl;
		break;
		
		case 4:
		cout <<"player "<< counter << endl << endl << "[: :] " << endl;
		break;
		
		case 5:
		cout <<"player "<< counter << endl << endl << "[:.:] " << endl;
		break;
		
		case 6:
		cout <<"player "<< counter << endl << endl << "[:::] " << endl;
		break;
	 
	}
}


Does this make sense to you? And thats what I meant when i said you could put all your couts on one line. This makes it much easier to read, and shaves off about 45 lines of unnecessary code.

EDIT:
Although to be perfectly honest, I'm not sure if endl works multiple times in a single cout. I don't see why it wouldn't but if this isn't the case feel free to correct me.
Last edited on
closed account (3qX21hU5)
Endl does work as many time in a single cout. Endl is the same as \n except it also flushes the buffer.
Ok I tried replacing the switch statement with your suggestion to see if it works but but it dosnt.
I did:

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
#include <time.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int dice1, dice2 = 0;
 
void RollDice(); // The Void Program That Rolls The Dice
 
int main()
 {
 srand(time(0));
 int input = 1;

int counter = 1
while(counter <= 2)
{
	switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1
	{
		case 1:
		cout <<"player "<< counter << endl << endl << "[ . ] " << endl;
		break;
	
		case 2:
		cout <<"player "<< counter << endl << endl << "[ : ] " << endl;
		break;
		
		case 3:
		cout <<"player "<< counter << endl << endl << "[. :] " << endl;
		break;
		
		case 4:
		cout <<"player "<< counter << endl << endl << "[: :] " << endl;
		break;
		
		case 5:
		cout <<"player "<< counter << endl << endl << "[:.:] " << endl;
		break;
		
		case 6:
		cout <<"player "<< counter << endl << endl << "[:::] " << endl;
		break;
	 
	}
}
You left out the dice1 = rand()%6+1
Now this compiles continiously. What did i do wrong?


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
#include <time.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int dice1=0, dice2 = 0;
 
void RollDice(); // The Void Program That Rolls The Dice
 
int main()
 {
 srand(time(0));
 int input = 1;
 int dice1;
 dice1 = (rand()%6+1);
 int counter = 1;
 

while(counter <= 2)
{
	switch(dice1) //Switch Statement That Has All The Possible Outcomes For Dice 1
	{
		case 1:
		cout <<"player "<< counter << endl << endl << "[ . ] " << endl;
		break;
	
		case 2:
		cout <<"player "<< counter << endl << endl << "[ : ] " << endl;
		break;
		
		case 3:
		cout <<"player "<< counter << endl << endl << "[. :] " << endl;
		break;
		
		case 4:
		cout <<"player "<< counter << endl << endl << "[: :] " << endl;
		break;
		
		case 5:
		cout <<"player "<< counter << endl << endl << "[:.:] " << endl;
		break;
		
		case 6:
		cout <<"player "<< counter << endl << endl << "[:::] " << endl;
		break;
	system ("Pause");
 return EXIT_SUCCESS;	
	}
}} 
Topic archived. No new replies allowed.