C++
You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user’s entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry and waits for that to happen.
Computer randomly chooses among scissors, rock or paper at each hand.
Scissors beats paper. Rock defeats scissors and paper whips rock.
It is highly recommended to have a modular implementation. Write a function which accepts two arguments one for computer’s choice and the other for the user’s pick and returns whether computer is winner of the hand or the user. You may also write two functions where one maps scissors, rock or paper to 3 positive integers with respect to an order and the other maps the other way around.
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <vector>
using namespace std;
void winner(string userChoice, string computerChoice, int&
computerScore, int& userScore) {
if (userChoice == computerChoice) {
return;
}
if (userChoice == "scissors") {
if (computerChoice == "rock")
{
computerScore++;
}
else {
userScore++;
}
return;
}
else if (userChoice == "rock") {
if (computerChoice == "scissors")
{
userScore++;
}
else {
computerScore++;
}
return;
}
else {
if (computerChoice == "scissors")
{
computerScore++;
}
else {
userScore++;
}
return;
}
}
int main()
{
vector < string > names(4);
names[1] = "scissors";
names[2] = "rock";
names[3] = "paper";
int computerScore = 0;
int userScore = 0;
srand(time(NULL));
while(true) {
cout << "Enter users's choice
: ";
string userChoice;
cin >> userChoice;
if (userChoice != names[1]
&& userChoice != names[2] && userChoice !=
names[3]) {
cout <<
"User's entry is not valid!" << endl;
continue;
}
string computerChoice =
names[rand() % 3 + 1];
cout << "Computer's choice is
: " << computerChoice << endl;
winner(userChoice, computerChoice,
computerScore, userScore);
if (computerScore == 3) {
cout <<
"The winner is computer!";
break;
}
else if (userScore == 3) {
cout <<
"The winner is user!";
break;
}
}
return 0;
}

comment down for any queries
please give a thumbs up
C++ You are asked to implement scissors-rock-paper game where the players are a computer and a...
You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...
IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....
(Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...
(c++ only)Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, the user enters his or her choice of “rock”, “paper”, or “scissors” at the keyboard using a menu in a function, userChoice, that returns a character. Next, there should be a function, computerChoice, that generates the computer’s play. A random number in the range of 1 through 3 is generated. If the...
Write this program using C++ , (Rock, Paper, Scissors Game – Page 373) This programming assignment is from the textbook with some slight modifications and clarifications. Here is what I am going to except from you. Your program should include at least the following functions: getComputerGuess(): this function should return a random value generated by the computer using rand function (read more about random numbers in Chapter 3 pages 126 – 128). getUsersChoice(): this function will ask the user to...
JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There are two players. Each player secretly chooses either, paper, rock or scissors. At the count of three, each player reveals what they have chosen. The winner of the game is determined this way: paper beats rock (because paper covers rock) rock beats scissors (because rock crushes scissors) scissors beat paper (because scissors cut paper) If the two players choose the same item, it is...
In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play the game of Rock, Paper, Scissors against the computer.Your program should have the following: •Make the name of the project RockPaperScissors•Write a method that generates a random number in the range of 1 through 3. The randomly generated number will determine if the computer chooses rock, paper, or scissors. If the number is 1, then the computer has chosen rock. If the number is...
C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...
C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats paper; paper beats rock. You must use these specific functions in your program. These are the prototypes: char generateP2toss(); int checkThrow(char, char); void printStatistics(int, int, int, int); void finalStatistics(int, int, int, int); void welcome(); Notes on these functions: generateP2toss() will generate the computer's toss (the computer is player2). It returns either an "r", "p", or "s/" checkThrow(char char) will check the throw by passing...
Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...