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
|
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string scp = "Scissors Cut Paper! ";
string rcs = "Rock Crushes Scissors! ";
string pcr = "Paper Covers Rock! ";
string w = " Wins! ";
string name1, name2, end;
string p1choice, p2choice;
int p1, p2, result;
cout << "Player 1, What is your name? " << endl;
getline(cin, name1);
cout << "Thank you, " << name1 << "! " << endl;
cout << "Player 2, What is your name? " << endl;
getline(cin, name2);
cout << "Thank you, " << name2 << "! " << endl;
do {
cout << "P1 Rock=1, Paper=2, Scissors=3 " << endl;
getline(cin, p1choice);
stringstream(p1choice) >> p1;
cout << "P2 Rock=1, Paper=2, Scissors=3 " << endl;
getline(cin, p2choice);
stringstream(p2choice) >> p2;
if ((p1 == 1) && (p2 == 1))
cout << "Rock vs Rock! Tie! " << endl;
else if ((p1 == 1) && (p2 == 2))
cout << pcr << name2 << w << endl;
else if ((p1 == 1) && (p2 == 3))
cout << rcs << name1 << w << endl;
else if ((p1 == 2) && (p2 == 1))
cout << pcr << name1 << w << endl;
else if ((p1 == 2) && (p2 == 2))
cout << "Paper vs Paper! Tie " << endl;
else if ((p1 == 2) && (p2 == 3))
cout << scp << name2 << w << endl;
else if ((p1 == 3) && (p2 == 1))
cout << rcs << name2 << w << endl;
else if ((p1 == 3) && (p2 == 2))
cout << scp << name1 << w << endl;
else if ((p1 == 3) && (p2 == 3))
cout << "Scissors vs Scissors! Tie! ";
else cout << "Oops! ";
cout << "Start Over? " << endl << "Q to quit, any other key to restart... "<< endl;
getline(cin, end);
} while (end != "Q");
return 0;
}
|