Rock, Paper, Scissors, Lizard, Spock issues

Hello,
I have to write the rock, paper, scissors, lizard, spock game. I'm having an issue on where to from where I currently am. The program must be divided into the following functions at least: int getUserChoice(), int getComputerChoice(), void determineWinner(int, int), void displayChoice(int). I'm working in the void displayChoice, but I'm not sure how to finish it or if I am even close to how it should be written. Any help would be appreciated thank you!


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
 #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int getUserChoice();
int getComputerChoice();
void determineWinner(int, int);
void displayChoice(int);

int main()
{
	cout << "Can you beat me at Rock, Paper, Scissors, Spock, Lizard?" << endl;
	cout << "Rules of the game are!" << endl;
	cout << "Scissors cuts Paper, Paper covers Rock, Rock crushes Lizard, Lizard poisons Spock, Spock smashes" << endl;
    cout <<" Scissors, Scissors decapitates Lizard, Lizard eats Paper, Paper disproves Spock, Spock vaporizes Rock, Rock crushes" << endl;
    cout <<" Scissors " << endl;
}
int getUsersChoice()
{
	int userschoice, Rock = 1, Paper = 2, Scissors = 3, Lizard = 4, Spock = 5;
	cout << "Please enter your choice: 1-Rock, 2-Paper, 3-Scissors, 4-Lizard, 5-Spock";
	cin >> userschoice;
	if ( userschoice == 1 )
	{
		cout << "You Chose: Rock" << endl;
	}
	else if ( userschoice == 2 )
	{
		cout << "You Chose: Paper" << endl;
	}
	else if ( userschoice == 3 )
	{
		cout << "You Chose: Scissors" << endl;
	}
	else if ( userschoice == 4 )
	{
		cout << "You Chose: Lizard" << endl;
	}
	else if ( userschoice == 5 )
	{
		cout << "You Chose: Spock" << endl;
}
int getComputerChoice();
{
	char compchar, compchoice;
	srand(time(0));
	compchoice = rand() % 5 + 1;
	if ( compchoice == 1 )
	{
		compchar = '1';
		cout << " Computer Chooses: Rock " << endl;
	}
	else if ( compchoice == 2 )
	{
		compchar = '2';
		cout << " Computer Chooses: Paper " << endl;
	}
	else if ( compchoice == 3 )
	{
		compchar = '3';
		cout << " Computer Chooses: Scissors " << endl;
	}
	else if ( compchoice == 4 )
	{
		compchar = '4';
		cout << " Computer Chooses: Lizard " << endl;
	}
	else if ( compchoice == 5 )
	{
		compchar = '5';
		cout << " Computer Chooses: Spock " << endl;
		return compchar;
	}
}
void determineWinner (int userschoice, int compchoice);
{
	int ususerschoiceer, compchoice;
	if ( ( userschoice == 1 && compchoice == '1' ) ||
	( userschoice == 2 && compchoice == '2' ) ||
	( userschoice == 3 && compchoice == '3' ) ||
	( userschoice == 4 && compchoice == '4' ) ||
	( userschoice == 5 && compchoice == '5' ) )
{
	cout << " It's a TIE! " << endl;
}
	else if (( userschoice == 3 && compchoice == '2' ) ||
	( userschoice == 2 && compchoice == '1' ) ||
	( userschoice == 1 && compchoice == '4' ) ||
	( userschoice == 4 && compchoice == '5' ) ||
	( userschoice == 5 && compchoice == '3' ) ||
	( userschoice == 3 && compchoice == '4' ) ||
	( userschoice == 4 && compchoice == '2' ) ||
	( userschoice == 2 && compchoice == '5' ) ||
	( userschoice == 5 && compchoice == '1' ) ||
	( userschoice == 1 && compchoice == '3' ))
{
	cout << "You Won. I'll get you next time." << endl;
}
	else if (( userschoice == 2 && compchoice == '3' ) ||
	( userschoice == 1 && compchoice == '2' ) ||
	( userschoice == 4 && compchoice == '1' ) ||
	( userschoice == 5 && compchoice == '4' ) ||
	( userschoice == 3 && compchoice == '5' ) ||
	( userschoice == 4 && compchoice == '3' ) ||
	( userschoice == 2 && compchoice == '4' ) ||
	( userschoice == 5 && compchoice == '2' ) ||
	( userschoice == 1 && compchoice == '5' ) ||
	( userschoice == 3 && compchoice == '1' ))
	{
		cout << "I won, Better luck next time!!" << endl;
	}
	return 0;
}
void displayChoice (int winner);
{
	int winner;

}
There are a number of errors in there:

1) after line 42 there should be an ending bracket, and there's a spelling error on line 78

2) in the determineWinner() function, there shouldn't be a return 0 line because the function was declared void, that's only reserved for the main() function

3) it would be a good idea to take out the options list in line 21 (Rock = 1, etc) because the program is going to get confused

4) take out the getUsersChoice() function and integrate it with the main() function, because it's pointless

5) there is no need for a displayChoice() function, because you already declared a winner

6) please in the terrible name of the Space Kraken don't put any type of argument into a void function, the point of them is to not return a variable

It's not really necessary to make functions when it would do just fine to put everything into main(). Other than that, it should be fine.
Last edited on
I wouldn't write the program like this but I have to for my class. These are the requirements for this assignment.

Rock, Paper, Scissors, Lizard, Spock game – Write a program that will play this game against the computer. The game should end once there is a winner. If the game is a tie then the program must make the user play again, until there is a winner. Once there is a winner, the program (game) must end. When the program begins, a random number is created between 1 and 5. These values will be used as follows:

1 – Rock
2 – Paper
3 – Scissors
4 – Lizard
5 – Spock

Use a menu to prompt the user for their choice, using the same values as above. The program should then display the computer's choice and indicate who has won. A winner is selected using the following rules:

Scissors cut paper
Paper covers rock
Rock crushes lizard
Lizard poisons Spock
Spock smashes (or melts) scissors
Scissors decapitate lizard
Lizard eats paper
Paper disproves Spock
Spock vaporizes rock
Rock breaks scissors

The program must be divided into the following functions at least:

int getUserChoice()
int getComputerChoice()
void determineWinner(int, int)
void displayChoice(int)

So right now I'm not sure where to go from here.
Topic archived. No new replies allowed.