Below is the solution:
code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int computerWin=0,userWin=0;
void playRockPaperScissor(char userChoice, char
computerChoice){
//check here for the computer wins of user win score
update when tie there is no score of both
if((computerChoice == 'r' || computerChoice == 'R')
&& (userChoice == 'r' || userChoice == 'R'))
{
cout << "It was a tie!"
<< endl;
}
else if ((computerChoice == 'p' || computerChoice ==
'P') && (userChoice == 'p' || userChoice == 'P'))
{
cout << "It was a tie!"
<< endl;
}
else if ((computerChoice == 's' || computerChoice ==
'S') && (userChoice == 's' || userChoice == 'S'))
{
cout << "It was a tie!"
<< endl;
}
else if ((computerChoice == 'r' || computerChoice ==
'R') && (userChoice == 's' || userChoice == 'S'))
{
cout << "Computer won!"
<< endl;
//userWin--;
computerWin++;
}
else if ((computerChoice == 'p' || computerChoice ==
'P') && (userChoice == 'r' || userChoice == 'R'))
{
//userWin--;
computerWin++;
cout << "Computer won!"
<< endl;
}
else if ((computerChoice == 's' || computerChoice ==
'S') && (userChoice == 'p' || userChoice == 'P'))
{
cout << "Computer won!"
<< endl;
//userWin--;
computerWin++;
} else {
cout << "You won!"
<< endl;
userWin++;
//computerWin--;
}
}
int main()
{
char userChoice;
char computerChoice[]="rps"; //computer choice char
array
int r;
unsigned seed;
do{
//The choices
cout <<
"\n===================\n";
cout << "R.
Rock\n";
cout << "P.
Paper\n";
cout << "S.
Scissors\n";
cout << "X. Quit the
game.\n";
cout <<
"===================\n";
cout << "Please enter
your choice::: ";
cin >>
userChoice;
//display the user
choice.
if (userChoice == 'R' ||
userChoice == 'r') //Rock
{
cout
<< "You picked Rock.\n";
}
else if (userChoice == 'P' ||
userChoice == 'p') //Paper
{
cout
<< "You picked Paper.\n";
}
else if (userChoice == 'S' ||
userChoice == 's') //Scissors
{
cout
<< "You picked Scissors.\n";
}
else if (userChoice == 'x' ||
userChoice == 'X') //Scissors
{
break;
}else{
cout<<"Wrong choice!";
exit(0);
}
//generate random number 1 to
3
seed = time(0);
srand(seed); //For the random
generator.
r = rand() % 3 + 1; //Computers
pick between 1 to 3 for r p s or R P S.
//assign the random number to the
computer choice char array to check for the r,p,s
if (computerChoice[r] == 'r')
//Rock
{
cout<< "Computer picked Rock.\n";
}
else if (computerChoice[r] ==
'p') //Paper
{
cout
<< "Computer picked Paper.\n";
}
else if (computerChoice[r] ==
's') //Scissors
{
cout
<< "Computer picked Scissors.\n";
}
playRockPaperScissor(userChoice,
computerChoice[r]); //method to play Rock Paper Scissor
//check for the computer win 3
times
if(computerWin==3){
cout <<
"\n==================================\n";
cout<<"*\tCongrats! Computer wins.\t*";
cout <<
"\n==================================\n";
break;
}
//check for the user win 3
times
if(userWin==3){
cout <<
"\n=================================\n";
cout<<"*\tCongrats! User wins.\t*";
cout <<
"\n=================================\n";
break;
}
}while(userChoice != 'x' || userChoice != 'X');
system("pause");
return 0;
}
sample output:
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: s
You picked Scissors.
Computer picked Scissors.
It was a tie!
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: s
You picked Scissors.
Computer picked Scissors.
It was a tie!
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: s
You picked Scissors.
Computer picked Scissors.
It was a tie!
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: s
You picked Scissors.
You won!
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: p
You picked Paper.
Computer picked Paper.
It was a tie!
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: r
You picked Rock.
Computer picked Paper.
Computer won!
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: s
You picked Scissors.
Computer picked Paper.
You won!
===================
R. Rock
P. Paper
S. Scissors
X. Quit the game.
===================
Please enter your choice::: r
You picked Rock.
Computer picked Scissors.
You won!
=================================
* Congrats! User
wins. *
=================================
You are asked to implement scissors-rock-paper game where the players are a computer and a user....
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...
It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...
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...
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...
Write a program in python that lets the user play the game 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. 2 corresponds to paper, and 3 corresponds to scissors. To set up the random number library, write the following at the top of your code: import random random.seed(300) Use...
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...
In python language
Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...
In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user to pick rock, paper, or scissors. Then, you’ll have the computer randomly choose one of the options. After that, print out the winner! You should keep playing the game until the user hits enter. Note: You’ll need to implement a method called String getWinner(String user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program....
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...