// A program that plays the game of Paper, Scissors, Rock! #include #include #include #include "Myro.h" using namespace std; bool beats (string me, string you) { // Does me beat you? If so, return true, false otherwise. if (me == "Paper" && you == "Rock") { // Paper beats rock return true; } else if (me == "Scissors" && you == "Paper") { // Scissors beat paper return true; } else if (me == "Rock" && you == "Scissors") { // Rock beats scissors return true; } else { return false; } } int main() { string items[] = {"Paper", "Scissors", "Rock"}; string choices = "Paper,Scissors,Rock"; // Randomize pseudo-random number generator srand(time(NULL)); // Play a round of Paper, Scissors, Rock! cout << "Let's play Paper, Scissors, Rock!\n"; cout << "In the window that pops up, make your selection>\n"; // Computer and Player make their selection... // Computer makes a selection string myChoice = items[rand() % 3]; // Player makes a selection string yourChoice = askQuestion("Pick an item.", choices); // inform Player of choices cout << endl; cout << "I picked " << myChoice << endl; cout << "You picked " << yourChoice << endl; // Decide if it is a draw or a win for someone if (myChoice == yourChoice) { cout << "We both picked the same thing.\n"; cout << "It is a draw.\n"; } else if (beats(myChoice, yourChoice)) { cout << "Since " << myChoice << " beats " << yourChoice << "...\n"; cout << "I win.\n"; } else { cout << "Since " << yourChoice << " beats " << myChoice << "...\n"; cout << "You win.\n"; } cout << "Thank you for playing. Bye!\n"; return 0; }