PROGRAM 2 Write an interactive program that plays the game of \"Rock, paper, sci
ID: 3788194 • Letter: P
Question
PROGRAM 2 Write an interactive program that plays the game of "Rock, paper, scissors." In this game, a player will be prompted to enter (or dislay a hand symbol representing) either "rock," "paper," or "scissors." The winner is the one whose choice dominates the other. Use a series of nested if statements to cover all possibilities. The rules are: l. paper dominates (wraps) rock 2. rock dominates (breaks) scissors 3. scissors dominate (cut) paper. EXAMPLE: WELCOME TO THE GAME OF ROCK PAPER OR SCISSORS!! PLAYER, please choose ROCK (0), PAPER (1), or SCISSORS (2). PLAYER: 0 You selected ROCK. The computer has randomly selected PAPER. SORRY, YOU LOST! The computer won because PAPER dominates (wraps) ROCK.Explanation / Answer
Answer:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
do{
string playerOption;
int system;
cout << "Are you ready to play Rock, paper, or scissors? " << endl;
cout << " " << endl;
cin >> playerOption;
cout << "Your entry: " << playerOption << endl;
cout << " " << endl;
srand(time(NULL));
system = rand() % 10 + 1;
if (system <= 3)
{
cout << "system entry: Rock" << endl;
cout << " " << endl;
}
else if (system <= 6)
{
cout << "system entry: Paper" << endl;
cout << " " << endl;
}
else if (system >= 7)
{
cout << "system entry: Scissors" << endl;
cout << " " << endl;
}
if (playerOption == "rock" && system <= 3)
{
cout << "It's a tie!" << endl;
cout << " " << endl;
}
else if (playerOption == "rock" && system <= 6)
{
cout << "You lose!" << endl;
cout << " " << endl;
}
else if (playerOption == "rock" && system >= 7)
{
cout << "You won the game" << endl;
cout << " " << endl;
}
if (playerOption == "paper" && system <= 3)
{
cout << "You won the game" << endl;
cout << " " << endl;
}
else if (playerOption == "paper" && system <= 6)
{
cout << "It is a tie" << endl;
cout << " " << endl;
}
else if (playerOption == "paper" && system >= 7)
{
cout << "You lost the game" << endl;
cout << " " << endl;
}
if (playerOption == "scissors" && system <= 3)
{
cout << "You lost the game" << endl;
cout << " " << endl;
}
else if (playerOption == "scissors" && system <= 6)
{
cout << "You won the game" << endl;
cout << " " << endl;
}
else if (playerOption == "scissors" && system >= 7)
{
cout << "It is a tie" << endl;
cout << " " << endl;
}
} while (cin.get());
cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.