Created
March 15, 2015 12:59
-
-
Save ImDevinC/74edb591a99cb1e48490 to your computer and use it in GitHub Desktop.
C++ Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//File Name: SourceCh3.cpp | |
//Author: Brandon Cabael | |
//Assignment : Chapter 3 | |
//Description: Create Rock Paper Scissors Game | |
//Last Changed: March 3, 2015 | |
//Including string for the P_1 and P_2 variables | |
#include<iostream> | |
#include<string> | |
using namespace std; | |
int main() | |
{ | |
//Declare variable | |
string P_1, P_2; | |
int REPLAY; | |
//Begin output of instructions to user | |
cout << "Press return after typing in your answer.\n"; | |
cout << "We are going to play a game of rock paper scissors!\n"; | |
cout << "For the purposes of this game, p=paper, r=rock, s=scissors\n"; | |
cout << "(Answers are not case-sensitive.)\n"; | |
//Begin input of player 1 | |
cout << "\nPlayer 1, which do you choose? Rock, paper or scissors? "; | |
cin >> P_1; | |
//Begin input of player 2 | |
cout << "\nPlayer 2, which do you choose? Rock, paper or scissors? "; | |
cin >> P_2; | |
cout << "\n"; | |
//Begin output of winner | |
if (((P_1 == "p") || (P_1 == "P")) && ((P_2 == "r") || (P_2 == "R"))) | |
cout << "Paper covers rock! Player 1 wins!\n"; | |
else if (((P_1 == "p") || (P_1 == "P")) && ((P_2 == "s") || (P_2 == "S"))) | |
cout << "Scissors cut paper! Player 2 wins!\n"; | |
else if (((P_1 == "r") || (P_1 == "R")) && ((P_2 == "p") || (P_2 == "P"))) | |
cout << "Paper covers rock! Player 2 wins!\n"; | |
else if (((P_1 == "r") || (P_1 == "R")) && ((P_2 == "s") || (P_2 == "S"))) | |
cout << "Rock breaks scissors! Player 1 wins!\n"; | |
else if (((P_1 == "s") || (P_1 == "S")) && ((P_2 == "p") || (P_2 == "P"))) | |
cout << "Scissors cuts paper! Player 1 wins!\n"; | |
else if (((P_1 == "s") || (P_1 == "S")) && ((P_2 == "r") || (P_2 == "R"))) | |
cout << "Rock breaks scissors! Player 2 wins!\n"; | |
else //(P_1 == P_2) | |
cout << "Nobody wins!\n"; | |
//Begin input from user if they want to play again | |
cout << "would you like to play again? (1 for yes) "; | |
cin >> REPLAY; | |
cout << "\n"; | |
//Begin if else statement to play again. | |
if (REPLAY == 1) | |
return main(); | |
else | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment