summaryrefslogtreecommitdiffstats
path: root/C++/Test2/RPS.cpp
blob: 7ca2f4b9974602f28179b986fbbae8f66b082671 (plain) (blame)
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
// Name: msglm
// Date: 
// Program Name: Rock Paper Scissors
// Description: Rock Paper Scissors


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

// Named constants

int main() {

	//Variable declaration
	int playerOneChoice;
	int playerTwoChoice;
	string result;
	string playerOneString;
	string playerTwoString;
	//Program title and description for the user
	cout << "Title: Rock Paper Scissors" << endl << "Description: Plays a game of Rock Paper Scissors. Input must be an integer." << endl << endl;

	// User input
	
	cout << "Player One, Make your choice:\n";
	cout << "1. Rock \n";
	cout << "2. Paper \n";
	cout << "3. Scissors \n";
	cout << "Player One Input: ";
	cin >> playerOneChoice;
	
	cout << "\nPlayer Two, Make your choice: \n";
	cout << "1. Rock \n";
	cout << "2. Paper \n";
	cout << "3. Scissors \n";
	cout << "Player Two Input: ";
	cin >> playerTwoChoice;


	if (playerOneChoice == playerTwoChoice){ //Draw
		result = "This match is a Draw";
	} else if (playerOneChoice == 1 && playerTwoChoice == 3){ //Rock Beats Scissors
		result = "Player One Victory";
	
	} else if (playerOneChoice == 2 && playerTwoChoice == 1){ //Paper Beats Rock
		result = "Player One Victory";
	
	} else if (playerOneChoice == 3 && playerTwoChoice == 2){ //Scissors Beats Paper
		result = "Player One Victory";
	} else { 
		//As the only winning moves and draw incurring moves have already 
		//be checked for player 1, we can assume a victory for two if this position is reached
		result = "Player Two Victory.";
	}

	//Convert the inputted number to a string for displaying back to the user
	switch(playerOneChoice) {
		case 1:
			playerOneString = "Rock";
			break;
		case 2:
			playerOneString = "Paper";
			break;
		case 3:
			playerOneString = "Scissors";
			break;
		default:
			cout << "Something went terribly wrong. Your input may have problems";
			return 1;
	}
	switch(playerTwoChoice) {
		case 1:
			playerTwoString = "Rock";
			break;
		case 2:
			playerTwoString = "Paper";
			break;
		case 3:
			playerTwoString = "Scissors";
			break;
		default:
			cout << "Something went terribly wrong. Your input may have problems";
			return 1;
	}

		//Output
		cout << "\n\n\nRESULTS:\n";
		cout << "Player" << setw(15) << "Choice \n";
		cout << "Player #1:" << setw(12) << playerOneString << endl;
		cout << "Player #2:" << setw(12) << playerTwoString << endl;
		cout << result << endl;
}

	/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
	 *
	 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
	 * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
	 */