Rock Paper Scissors help plz

this is the code for a rock paper scissors game it is not completed yet but is the idea there and is there any thing that needs ti be fixed

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

using namespace std;

void getCompChoice(string);
void getUserChoice(string);
void getWinner();



int main ()
{
	string compChoice, userChoice, again;
	char play;

	cout << " The conputer would like to play a game. \n";
	cout << "Would you like to play ?\n";
	cout << "(Input a Y to begin)";
	cin >> play;

	while (play == 'Y' || play = "y");

	userChoice = getUserInput(string);

	getCompChoice (compChoice);

	cout << "The computer chose" << compChoice;

	getWinner(userChoice, compChoice);

}

void getCompChoice(string choice)
{
	int compChoiceA = 1 + rand() % 3;

	if (compChoiceA == 1)
		choice = "Rock";
	else if (compChoiceA == 2)
		choice = "Paper";
	else
		choice = "Scissors";
}


void getUserInput (string){
	int selection;
	string choiceA;

	cout << "Please enter your choice";
	cout << "Enter 1 for Rock, 2 for Paper, and 3 for Scissors";
	cin >> selection;

	if (selection == 1)
		choiceA = "Rock";
	else if (selection == 2)
		choiceA = "Paper";
	else
		choiceA = "Scissors";
	return choiceA;
}


void getWinner (string user, string comp){
if (user == "Rock")
	if (comp == "Paper");
		cout << "Paper covers Rock! Computer wins!";
	else if (comp == "Scissors")
		cout << "Rock smashes Scissors! Player Wins!";
	else 
		cout << "It is a tie!";
else if
well immediately your first while loop ends with a semicolon so unless you want it to do nothing... which is pointless, get some nice brackets in there. you also arent storing storing your computers choice in a variable, and you havent passed choice as a reference so the data is just being lost. youre also missing braces at the end of getWinner and have a random elseif at the end... have you even tried compiling this yet?
Last edited on
yeah i realized that
the code is also being translated from a couple of pages of pseudocode that i write up a few days ago
here is the completed code but i am still getting alot of red error lines


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

using namespace std;

void getCompChoice(string);
void getUserChoice(string choiceA);
void getWinner();



int main ()
{
	string compChoice, userChoice, again;
	char play;

	cout << " The conputer would like to play a game. \n";
	cout << "Would you like to play ?\n";
	cout << "(Input a Y to begin)";
	cin >> play;

	while (play == 'Y' || play = "y"){

	userChoice = getUserInput();

	getCompChoice (compChoice);

	cout << "The computer chose" << compChoice;

	getWinner(userChoice, compChoice);
	}

}

void getCompChoice(string choice)
{
	int compChoiceA = 1 + rand() % 3;

	if (compChoiceA == 1)
		choice = "Rock";
	else if (compChoiceA == 2)
		choice = "Paper";
	else
		choice = "Scissors";
}


void getUserInput (string choiceA){
	int selection;
	string choiceA;

	cout << "Please enter your choice";
	cout << "Enter 1 for Rock, 2 for Paper, and 3 for Scissors";
	cin >> selection;

	if (selection == 1)
		choiceA = "Rock";
	else if (selection == 2)
		choiceA = "Paper";
	else
		choiceA = "Scissors";
	return choiceA;
}


void getWinner (string user, string comp){
if (user == "Rock")
	if (comp == "Paper");
		cout << "Paper covers Rock! Computer wins!";
	else if (comp == "Scissors")
		cout << "Rock smashes Scissors! Player Wins!";
	else 
		cout << "It is a tie!";
else if (user == "Paper")
	if (comp == "Rock");
		cout << "Paper covers Rock! Player Wins!";
	else if (comp == "Scissors")
		cout << "Scissors cut Paper! Computer Wins!";
	else 
		cout << "It is a tie!";
else 
	
	if (comp == "Rock");
		cout << "Rock smashes Scissors! Computer wins!";
	else if (comp == "Paper")
		cout << "Scissors cut Paper! Player Wins!";
	else 
		cout << "It is a tie!";
}
no reason it should be that long. this is my try, and while perhaps its not the most efficient code as it uses cin and system commands, but whatever! :)
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::endl;
using std::cin;
int compChoice();
void winner(int compChoice, int playerChoice);

int main(void)
{
	int choice;
	char again = 'y';
	srand(time(0));

	do
	{
		cout << "1. Rock" << endl << "2. Paper" << endl << "3. Scissors" << endl << "Choice: " << endl;
		cin >> choice;
		
		int secondChoice = compChoice();
		winner(secondChoice, choice);
		
		cout << "Again? Y/N ";
		cin >> again;
		system("CLS");
	} while (again == 'Y' || again == 'y');
	
	return 0;
}

int compChoice()
{
	return (rand() % 3) + 1;
}

void winner(int compChoice, int playerChoice)
{
	if (playerChoice == compChoice)
	{
		cout << "Same thing was chosen by both, try again!" << endl;
		main();
	}

	if (compChoice == 3)
		cout << "Computer chose scissors" << endl;
	else if(compChoice == 2)
		cout << "Computer chose paper" << endl;
	else
		cout << "Computer chose rock" << endl;

	if ((playerChoice == 1 && compChoice == 3) || (playerChoice == 2 && compChoice == 1) || (playerChoice == 3 && compChoice == 2))
		cout << "You won" << endl;
	else
		cout << "You lost" << endl;
	
	return;
}
Last edited on
thanks for the help i will go over my code now and see if anything else comes up
now i seem to be having trouble with the if else if in the getWinner function of my code can someone help me with this set of errors
Last edited on
youre not telling us anything. people wont help you if you dont tell us what there errors are. just try to steal some stuff from my code?
r u in csc 110 lol tcc?
Topic archived. No new replies allowed.