Rock Paper Scissors Help

Hi all, this is my first post. I need some help with my code for Rock, Paper, Scissors. The program runs but when I choose, for example, rock, and the computer chooses scissors it gets mixed up. This is what it reads out:

********************************************

Select one of the following options
1. Rock
2. Paper
3. Scissors
or
4. Quit
Choice: 1

You picked Rock.
The computer picked Scissors.
You lose! Paper covers Rock.

Hit the Enter key to continue
************************************************************
This is my code, can anyone tell me what is causing that? I'm stuck.

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
 #include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;


void ProgramInfo();
int GetUserChoice();
int GetComputerChoice();
int DetermineAndDisplayWinner(int user, int comp);
void PrintObject(int obj);
void Pause();

const int Rock = 1, Scissors = 2, Paper = 3;

int main()
{
	int userch, compch, WLD;
	int count = 0, win = 0, lose = 0, draw = 0;
	
	ProgramInfo();


	do
	{

		do
		{

			userch = GetUserChoice();
			if (userch == 4 && count == 0)
			{
				cout << "This program will now end." << endl;
				exit(0);
			}
			else if (userch == 4)
			{
				cout << "Number of Games Played: " << count << endl;
				cout << "You Won:                " << win << endl;
				cout << "The Computer Won:	" << lose << endl;
				cout << "Number of Ties:         " << draw << endl;
				cout << endl;
				cout << "Thank you for playing Rock, Paper, Scissors." << endl;
				exit(0);
			}
			else if (userch > 4 || userch < 1)
				cout << "Please enter an integer from the menu.\n" << endl;

		} while (userch > 4 || userch < 1);

		compch = GetComputerChoice();
		WLD = DetermineAndDisplayWinner(userch, compch);
		if (WLD == 1)
		{
			win++; count++;
		}
		else if (WLD == 2)
		{
			lose++, count++;
		}
		else
		{
			draw++, count++;
		}

	} while (!(userch == 4));



		return 0;
	}


void ProgramInfo()
{

	cout << "This is Rock, Paper, Scissors! Pick an option" << endl;
	cout << "from below and have fun!" << endl;
	cout << endl;

}

void Pause()
{
	cin.ignore(80, '\n');
	cout << "Hit the Enter key to continue" << endl;
	cin.get();
}

int GetUserChoice()
{

	int choice;
	cout << "Select one of the following options" << endl;
	cout << "1. Rock" << endl;
	cout << "2. Paper" << endl;
	cout << "3. Scissors" << endl;
	cout << "or" << endl;
	cout << "4. Quit" << endl;
	cout << "Choice: ";


	cin >> choice;
	cout << endl;
	return choice;
}

int GetComputerChoice()
{

	int choice;
	srand(static_cast<unsigned int> (time(0)));
	choice = 1 + rand() % 3;
	return choice;
}

int DetermineAndDisplayWinner(int user, int comp)
{
	int WLD;
	cout << "You picked ";
	PrintObject(user);
	cout << "." << endl;
	cout << "The computer picked ";
	PrintObject(comp);
	cout << "." << endl;

	if (user == Rock && comp == Paper)
	{
		cout << "You lose! Paper covers Rock.\n" << endl;
		Pause();
		cout << endl;
		WLD = 2;
	}

	else if (user == Paper && comp == Scissors)
	{
		cout << "You lose! Scissors cuts Paper.\n" << endl;
		Pause();
		cout << endl;
		WLD = 2;
	}
	
	else if (user == Scissors && comp == Rock)
	{
		cout << "You lose! Rock smashes Scissors.\n" << endl;
		Pause();
		cout << endl;
		WLD = 2;
	}

	else if (user == Rock && comp == Scissors)
	{

		cout << "You win! Rock smashes Scissors.\n" << endl;
		Pause();
		cout << endl;
		WLD = 1;
	}

	else if (user == Paper && comp == Rock)
	{
		cout << " You win! Paper covers Rock.\n" << endl;
		Pause();
		cout << endl;
		WLD = 1;

	}

	else if (user == Scissors && comp == Paper)
	{
		cout << "You win! Scissors cuts Paper.\n" << endl;
		Pause();
		cout << endl;
		WLD = 1;
	}

	else
	{
		cout << "Tie game." << endl;
		cout << endl;
		Pause();
		WLD = 3;
	
	}

	return WLD;
}

void PrintObject(int obj)
{
	switch (obj)
	{
		case 1:
			cout << "Rock";
			break;
		case 2: 
			cout << "Paper";
			break;
		case 3: 
			cout << "Scissors";
			break;
	}
}
In the constant declaration you say Scissors = 2 and Paper = 3, but in PrintObject you say 2 is Paper and 3 is Scissors
Last edited on
Oh wow haha, thanks so much I appreciate it!
Topic archived. No new replies allowed.