declaring winner

The bottom if else statement doesn't seem to declare a winner and always endsin a draw no matter the score.

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
 
#include "pch.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;




int main()
{	// dice 1-3 for player 4-6 for computer
	int turns; // turn
	int dice1;
	int dice2;
	int dice3;
	int dice4;
	int dice5;
	int dice6;
	int paircount = 0;			 // counter to keep track of number of pairs for player
	int tokcount = 0;			// counter to keep track of number of three of a kind for player
	int computerpaircount = 0;   // same as above but for computer
	int computertokcount = 0;
	int turnsCounter = 1;	   // shows what turn player in on







	cout << "please enter number of turns you wish to play" << endl;
	cin >> turns;

	cout << "Number of turns you wish to play:" << turns << endl;

	do {

		cout << "Turn: " << turnsCounter << endl; // will keep track of turns through game

		srand(time(0));

		dice1 = rand() % 6 + 1;
		dice2 = rand() % 6 + 1;
		dice3 = rand() % 6 + 1;
		dice4 = rand() % 6 + 1;
		dice5 = rand() % 6 + 1;
		dice6 = rand() % 6 + 1;




		cout << "you roll: " << dice1 << " " << dice2 << " " << dice3 << endl;	// outputes dice for player

		cout << "computer rolls " << dice4 << " " << dice5 << " " << dice6 << endl; // outputs dice for computer
		// below checks if dice match for player
		if (dice1 == dice2 == dice3) {

			cout << "You got a three of a kind: " << "50 points" << endl;

			tokcount++;
		}

		else if (dice1 == dice2 or dice2 == dice1) {

			cout << "You got a Pair " << " 25 points" << endl;
			paircount++;
		}

		else if (dice2 == dice3 or dice3 == dice2) {

			cout << "You got a Pair " << "25 points" << endl;
			paircount++;

		}
		else if (dice1 == dice3 or dice3 == dice1) {

			cout << "You got a pair " << "25 points" << endl;
			paircount++;
		}
		// below checks if dice match for computer
		if (dice4 == dice5 == dice6) {

			cout << "computer got a Three of a kind: " << "50 points" << endl;
			computertokcount++;
		}
		else if (dice4 == dice5 or dice5 == dice4) {

			cout << "Computer got a pair: " << "25 points" << endl;
			computerpaircount++;

		}
		else if (dice4 == dice6 or dice6 == dice4) {

			cout << "computer got a pair: " << "25 Points" << endl;
			computerpaircount++;
		}
		else if (dice5 == dice6 or dice6 == dice5) {

			cout << "computer got a pair: " << "25 points" << endl;
			computerpaircount++;

		}





		// turn counter 
		if (turns >= 0) {

			// allows player to leave the game or continue playing
			cout << "would you like to go again" << endl;
			cout << "/N or /Y" << endl;
			string choice;
			cin >> choice;
			if (choice == "/N") {
				cout << "thanks for playing" << endl;
				break;
			}
			else if (choice == "/n") {
				cout << "thanks for playing" << endl;
				break;
			}
			else if (choice == "/Y") {



			}
			else if (choice == "/y") {


			}




			// makes sure turns count down
			turns--;
			turnsCounter++;
		}




	} while (turns >= 1);





	//used to test counts (just remove comments) to check if math is correct
   /* cout << "playertokcount" << " " << tokcount << endl;
	cout << "playerpaircount" << " " << paircount << endl;
	cout << " " << endl;
	cout << "computertokcount" << " " << computertokcount << endl;
	cout << "computerpaircount" << " " <<computerpaircount << endl;
	*/

	cout << "Player Score: " << tokcount * 50 + paircount * 25 << endl;
	cout << "====================" << endl;
	cout << "computer Score: " << computertokcount * 50 + computerpaircount * 25 << endl;
	
	int playerScore = tokcount * 50 + paircount * 25 ;
	
	int computerScore = computertokcount * 50 + paircount * 25 ;

	if (playerScore > computerScore) {

		cout << "you win!" << endl;
	}

	else if (playerScore < computerScore) { 
		cout << "you lose" << endl; }
	
	else cout << "Draw" << endl;

	

	return 0;
}
> int computerScore = computertokcount * 50 + paircount * 25 ;
Who's pair count?
Thanks for pointing that out.(it's suppose to say computerpaircount) However it still couts a draw.


Last edited on
Well it works for me.
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
$ g++ foo.cpp
$ ./a.out 
please enter number of turns you wish to play
1
Number of turns you wish to play:1
Turn: 1
you roll: 2 5 5
computer rolls 3 2 6
You got a Pair 25 points
would you like to go again
/N or /Y
/N
thanks for playing
Player Score: 25
====================
computer Score: 0
you win!
$ ./a.out 
please enter number of turns you wish to play
1
Number of turns you wish to play:1
Turn: 1
you roll: 6 5 3
computer rolls 3 6 3
computer got a pair: 25 Points
would you like to go again
/N or /Y
/N
thanks for playing
Player Score: 0
====================
computer Score: 25
you lose
Thank you! I copied and pasted my code into a new project and it worked.
Topic archived. No new replies allowed.