summaryrefslogtreecommitdiffstats
path: root/C++/Test2/RPS.cpp
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
committermsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
commit9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch)
treeeb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/Test2/RPS.cpp
downloadschool-code-master.tar.gz
school-code-master.tar.bz2
school-code-master.zip
Inital CommitHEADmaster
Diffstat (limited to 'C++/Test2/RPS.cpp')
-rw-r--r--C++/Test2/RPS.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/C++/Test2/RPS.cpp b/C++/Test2/RPS.cpp
new file mode 100644
index 0000000..7ca2f4b
--- /dev/null
+++ b/C++/Test2/RPS.cpp
@@ -0,0 +1,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/>.
+ */
+