assistance in editing rock paper scissors program

Hello,

I created this rock paper scissors script and was hoping to see if someone had any advice to make the script shorter and more sufficient.

The script does what I need it to do but if there are better ways to write it I would like to know.

Thank you, here is the script and the rules I have to follow.

•Program should be able to handle input of capital or lower-case letters (Both 'R' and 'r' mean "Rock")

•Should use at least one switch statement or at least one multi-way if-statement (using "else if").

•Should use at least one logical AND or OR in your program (written like: && ||)

•Should always output who won or whose move was invalid (unless there's a tie).


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

int main()
{

//Assign Variables

char player1[21], player2[21], player1Choice, player2Choice;

char rockBeatsScissors[240] = "\nScissors try to cut rock, which then dulls" 
			     " scissors blade...\n\nScissors die...\n\n";

char paperBeatsRock[240] = "\nRock tries to roll over paper and misses,\n\n"
			   "paper lays itself on rock suffocating it."	
			   "\n\nRock dies...\n\n";

char scissorsBeatsPaper[240] = "\nPaper lunges at scissors but quickly realizes"
			       " it's outmatched.\n\nScissors cuts paper into"
			       " pieces...\n\n";

char tieGame[240] = "\n\nTIE GAME, EVERYONE LOSES!\n\n";

cout << "\nWelcome to Rock, Paper, Scissors 9000\n\n";

cout << "Player 1 enter your name: ";
cin >> player1;

cout << "\nPlayer 2 enter your name: ";
cin >> player2;

cout << "\n\nPress [R] for rock\n";
cout << "Press [P] for paper\n";
cout << "Press [S] for scissors\n\n";

cout << player1 << " it's your turn: ";
cin >> player1Choice; 

cout << "\n" << player2 << " it's your turn: ";
cin >> player2Choice;

if (player1Choice == 'r' || player1Choice ==  'R')
{	
	if(player2Choice == 'r' || player2Choice == 'R')
		cout << tieGame << endl;

	else if(player2Choice == 'p' || player2Choice == 'P')
	{
		cout << paperBeatsRock << endl;
		cout << player2 << " WINS\n" << endl;
	}

	else if(player2Choice == 's' || player2Choice == 'S')
	{
		cout << rockBeatsScissors << endl;		
  		cout << player1 << " WINS\n" << endl;
	}


	else
		cout << "\nINVALID SELECTION " << player2 << endl;
	
}

else if (player1Choice == 'p' || player1Choice == 'P')
{
	if(player2Choice == 'r' || player2Choice == 'R')
	{	cout << paperBeatsRock << endl;
		cout << player1 << " WINS\n" << endl;
	}

	else if(player2Choice == 'p' || player2Choice == 'P')
		cout << tieGame << endl;

	else if(player2Choice == 's' || player2Choice == 'S')
	{
		cout << scissorsBeatsPaper << endl;		
  		cout << player2 << " WINS\n" << endl;
	}

	else
		cout << "\nINVALID SELECTION " << player2 << endl;
	

}

else if (player1Choice == 's' || player1Choice == 'S')
{
	if(player2Choice == 'r' || player2Choice == 'R')
	{	cout << rockBeatsScissors << endl;
		cout << player2 << " WINS\n" << endl;
	}

	else if(player2Choice == 'p' || player2Choice == 'P')
	{
		cout << scissorsBeatsPaper << endl;
		cout << player1 << " WINS\n" << endl;
	}

	else if(player2Choice == 's' || player2Choice == 'S')
		cout << tieGame << endl;

	else
		cout << "\nINVALID SELECTION " << player2 << endl;
	

}

else
{
cout << "\nINVALID SELECTION " << player1 << endl;
}

}


Deadline for this program is today if someone could please help out....

The code does what I need it to do just fine, but I feel like it could still use a lot of work..

For instance

cout << "\nINVALID SELECTION " << player2 << endl;

I had to use this line 3 different times in my code...

Is 114 lines to much for a program like this?
Last edited on
Topic archived. No new replies allowed.