diff options
Diffstat (limited to 'C++/Test2/RPS.cpp')
-rw-r--r-- | C++/Test2/RPS.cpp | 101 |
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/>. + */ + |