Rock Paper Scissors Game for Project plz Help

Hi I need to make rock, paper and scissors game for my project.
I was stuck and don't know what I did wrong in the program.
Thanks in advance.

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
//Rock paper scissors game

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;
void showMenu();

int main()
{
	int userChoice, pcChoice, result;	//hold menu

	//seed random num generator
	srand(static_cast<unsigned int>(time(0)));

	//constant for menu choices
	const int ROCK_CHOICE = 1;
	const int PAPER_CHOICE = 1;
	const int SCISSORS_CHOICE = 3;
	const int QUIT_CHOICE = 4;

	//random seed 
	srand(time(NULL));
	//computer random choice
	int pcChoice = rand() % 3 + 1;

	//set up numeric output formatting
	cout << fixed << showpoint << setprecision(3);

	do
	{
		// display menu and get userchoice
		showMenu();
		cin >> userChoice;

		//validate menu selection
		while (userChoice < ROCK_CHOICE || userChoice > QUIT_CHOICE)
		{
			cout << "Please enter a valid menu choice: ";
			cin >> userChoice;
		}

		// if user and pc made same choice
		while (userChoice = pcChoice)
		{
			cout << "It is a tie! Please play again: ";
			cin >> userChoice;
		}
	}

	//If not proceed the game
	if (userChoice != QUIT_CHOICE)
		//display pcChoice
		cout << "pc Choice is " << pcChoice << endl;
	//display result 
	switch (userChoice)
	{
		case userChoice = pcChoice
			cout << "It is a tie!\n";
			break;

			case userChoice = 1 && pcChoice = 3
				cout << "The rock smash the scissors, you lose!\n";
				break;

				case userChoice = 3 && pcChoice = 1
					cout << "The rock smash the scissors, you win!\n";
					break;

					case userChoice = 3 && pcChoice = 2
						cout << "Scissors cuts paper, you win!\n";
						break;

						case userChoice = 2 && pcChoice = 3
							cout << "Scissors cuts paper, you lose!\n";
							break;

							case userCHoice = 2 && pcChoice = 1
								cout << "Paper wrap rock, you win!\n";
								break;

								case userChoice = 1 && pcChoice = 2
									cout << "Paper wrap rock, you lose!\n";
									break;
	}
} while (userChoice != QUIT_CHOICE);
 return 0;
}

	// outside the int for menu
	void showMenu()
	{
		cout << "\n\t\tWelcome to the Rock, Paper, and Scissors Game!\n\n"
			<< "Please enter your choice in number: \n"
			<< "1. Rock\n"
			<< "2. Paper\n"
			<< "3. Scissors\n"
			<< "4. Quit\n";
	}

	void showResult(int userChoice, int pcChoice)
	{
		if (userChoice == 1 && pcChoice == 3)
			cout << "The rock smashes the scissors!"

		else if (userChoice == 3 && pcChoice == 2)
		cout << "Scissors cuts paper"

		else if (userChoice == 2 && pcChoice == 1)
		cout << "Paper wraps rock"
	}
	
	
if you execute the shell , you have this result:


 In function 'int main()':
27:6: error: redeclaration of 'int pcChoice'
13:18: note: 'int pcChoice' previously declared here
46:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
54:5: error: expected 'while' before '(' token
56:3: error: expected ';' before 'cout'
60:21: error: expression '(userChoice = pcChoice)' is not a constant-expression
60:21: error: expression '(userChoice = pcChoice)' is not a constant-expression
61:4: error: expected ':' before 'cout'
64:36: error: lvalue required as left operand of assignment
65:5: error: expected ':' before 'cout'
68:37: error: lvalue required as left operand of assignment
69:6: error: expected ':' before 'cout'
72:38: error: lvalue required as left operand of assignment
73:7: error: expected ':' before 'cout'
76:39: error: lvalue required as left operand of assignment
77:8: error: expected ':' before 'cout'
80:13: error: 'userCHoice' was not declared in this scope
80:40: error: lvalue required as left operand of assignment
81:9: error: expected ':' before 'cout'
84:41: error: lvalue required as left operand of assignment
85:10: error: expected ':' before 'cout'
13:28: warning: unused variable 'result' [-Wunused-variable]
20:12: warning: unused variable 'PAPER_CHOICE' [-Wunused-variable]
21:12: warning: unused variable 'SCISSORS_CHOICE' [-Wunused-variable]
 At global scope:
88:3: error: expected unqualified-id before 'while'
89:2: error: expected unqualified-id before 'return'
90:1: error: expected declaration before '}' token
 
Last edited on
then:

1) line 27: cancel type 'int before pcchoice;
2) line 46 : on while condition change '=' with '==' ;
on alternative: from line 39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
           	while (userChoice < ROCK_CHOICE || userChoice > QUIT_CHOICE)
		{
			cout << "Please enter a valid menu choice: ";
			cin >> userChoice; 
                        if( userchoice == pcChoice )
                        {
                                continue ;
                        }
                        else
                        {
                                break :
                        } 
		}


3) line 88 : move do/while condition from this line at line 51 ; //and delete braches

4) please read this for switch statement: // essential
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Be more careful as you write, and try the program out a few times as you're writing it. Don't try to write the whole thing and hope it works, but make incremental changes and see improvement.

1. You have many typos.
1a. You set both ROCK and PAPER to 1.
1b. Many cases of Variable Assignment(=) instead of Check for Equality (==)
1c. One of your win cases was reversed (rock should beat scissors)
1d. "pc" choice should be inside the game loop so that it changes if the user does not want to quit

2. Use better spacing/formatting. Click near the brackets and your editor should highlight both the start and end to help you out, so that you can see where it starts and ends --> you basically mis-aligned a bunch of stuff

3. switch(var) is for many simple comparisons against var. In this case you're checking many conditions, so use
1
2
3
4
5
6
7
8
9
10
11
if(...)
{
...
}
else if(...) // A bunch of these
{
...
}
else  // In case of errors; default case
{
}


4. Add descriptions like a DESC array. Otherwise it'll just say "pc Choice is 1" -- what is 1?
4b. (related) compare things with your const variables, like PAPER, ROCK, etc. Don't continue to compare against 1,2,3 when you can make it clearer for the reader of the code.

Edit: on second thought, noticed you said project. Redacted fixed code for now. Try to improve it yourself and get closer first (at least compiling).
Last edited on
Topic archived. No new replies allowed.