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:
Note that each game is a rapid-fire round until the user enters "q" to quit. Then those game statistics are displayed.
Allow your user to repeat the entire program if desired. Don't forget input validation loops.
Format your output like this (or improve on it):
***ROCK, PAPER, SCISSORS GAME***
Directions: enter one of these to throw down:
r: rock
p: paper
s: scissors
q: quit and display statistics
> Rock Paper Scissors Throw! r/p/s/q > r
> Lose.
> Rounds: 1 | P1 wins: 0 | Computer wins: 1 | Ties: 0
> Rock Paper Scissors Throw! r/p/s/q > r
> Tie!
> Rounds: 2 | P1 wins: 0 | Computer wins: 1 | Ties: 1
> Rock Paper Scissors Throw! r/p/s/q > t
> ERROR: only pick from {r, p, s, q} > s
> Tie!
> Rounds: 3 | P1 wins: 0 | Computer wins: 1 | Ties: 2
> Rock Paper Scissors Throw! r/p/s/q > p
> Tie!
> Rounds: 4 | P1 wins: 0 | Computer wins: 1 | Ties: 3
> Rock Paper Scissors Throw! r/p/s/q > p
> Win!
> Rounds: 5 | P1 wins: 1 | Computer wins: 1 | Ties: 3
> Rock Paper Scissors Throw! r/p/s/q > q
*************
Game results:
*************
Player 1 wins: 1 (20.00%)
Computer wins: 1 (20.00%)
Ties: 3 (60.00%)
Rounds: 5
> Play another entire game (Y/N)? > y
> Rock Paper Scissors Throw! r/p/s/q > r
> Lose.
> Rounds: 1 | P1 wins: 0 | Computer wins: 1 | Ties: 0
> Rock Paper Scissors Throw! r/p/s/q > q
*************
Game results:
*************
Player 1 wins: 0 (0.00%)
Computer wins: 1 (100.00%)
Ties: 0 (0.00%)
Rounds: 1
> Play another entire game (Y/N)? > n
> Game ending....#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
char generateP2toss();
int checkThrow(char, char);
void printStatistics(int, int, int, int);
void finalStatistics(int, int, int, int);
void welcome();
int main()
{
label:
cout<<endl;
//welcome() generates you welcome message and instructions.
welcome();
int p1 ,p2, tie, count;
p1=0;
p2=0;
tie=0;
count=0;
while(1)
{
cout<<"> Rock Paper Scissors Throw! r/p/s/q
>";
char p2c= generateP2toss();
char p1c;
int flag=1;
while(flag==1)
{
cin>>p1c;
if(p1c=='r'|| p1c=='p'|| p1c=='s'|| p1c=='q')
{
flag=0;
}
else
{
cout<<"ERROR: only pick from {r, p, s, q} >";
flag=1;
}
}
if(p1c=='q')
{
finalStatistics(p1,p2,tie ,count);
cout<<" > Play another entire game (Y/N)? > ";
char op;
cin>>op;
if(op=='N' || op=='n')
{
cout<<">Game ending....."<<endl;
break;
}
else if(op=='Y' || op=='y')
goto label;
}
int r=checkThrow(p1c,p2c);
count++;
if(r==0)
{
tie++;
cout<<"Tie!"<<endl;
}
else if(r==1)
{
p1++;
cout<<"Win!"<<endl;
}
else if(r==2)
{
p2++;
cout<<"Lose!"<<endl;
}
printStatistics(p1, p2, tie, count);
cout<<endl;
}
}
//welcome() generates you welcome message and instructions.
void welcome()
{
cout<<" ***ROCK, PAPER, SCISSORS GAME***
"<<endl<<endl<<endl<<endl;
cout<<"Directions: enter one of these to throw down: "<<endl;
cout<<"r: rock"<<endl;
cout<<"p: paper"<<endl;
cout<<"s: scissors"<<endl;
cout<<"q: quit and display statistics"<<endl;
}
char generateP2toss()
{
char ar[3]={'r','s','p'};
// Use current time as
// seed for random generator
srand(time(0));
int num = (rand() % (2 +1));
return ar[num];
}
// to check reuslt
//will check the throw by passing the player1 and player2 throws.
It returns an integer: 0 for a tie, 1 for player1 winning, and 2
for player2/computer winning.
int checkThrow(char p1c, char p2c)
{
if(p1c==p2c)
return 0;
else if((p1c=='r' && p2c=='s')|| (p1c=='s' &&
p2c=='r'))
{
if(p1c=='r')
return 1;
else
return 2;
}
else if((p1c=='s' && p2c=='p')||( p1c=='p' &&
p2c=='s'))
{
if(p1c=='s')
return 1;
else
return 2;
}
else if((p1c=='p' && p2c=='r')|| (p1c=='r' &&
p2c=='p'))
{
if(p1c=='p')
return 1;
else
return 2;
}
}
//prints the statistics for each throw. Parameters are the number
of times player1 has won, player2 wins, ties, and the number of
rounds.
void printStatistics(int p1, int p2, int tie, int count)
{
cout<<"> Rounds: "<<count<<" | P1 wins:
"<<p1<<" | Computer wins: "<<p2<<" | Ties:
"<<tie<<endl;
}
void finalStatistics(int p1, int p2, int tie, int count)
{
cout<<"*************"<<endl<<endl;
cout<<"Game results: "<<endl<<endl;
cout<<"*************"<<endl<<endl;
float f1=(((float)p1/count)*100);
float f2=(((float)p2/count)*100);
float f3=(((float)tie/count)*100);
cout<< "Player 1 wins: "<< p1<<" "<<"
("<<f1<<"%)"<<endl;
cout<< "computer wins: "<< p2<<" "<<" ("<<f2<<"%)"<<endl;
cout<< "Ties : "<< tie<<" "<<"
("<<f3<<"%)"<<endl;
cout<<"Rounds: " << count<<endl;
}


Please upvote me it took lot of time
for any queries plzz comment :)
C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats...
This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going 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...
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...
Objective: Write a program that simulates a game of rock, paper, scissors between a human and the computer in best 2 out of 3 rounds. Requirements: . The player can enter either "rock", "paper", or "scissors'". o If the player enters anything other than that the computer automatically gets a point . The computer randomly selects one of the gestures o Use the Random type to make this easier o Also make sure you import java.util.Random o You can use...
Rock, Paper, Scissors - Write a MATLAB script file to play Rock, Paper, Scissors with the computer. x=rand; if x< 1/3 then it is Rock, if l/3<= x < 2/3 it is Paper else it is Scissors end if This is how the game should look like on the screen: Enter "r" for Rock, "p" for Paper, or "s" for Scissors", or enter "q" to Quit the game r leftarrow say, this is what you entered Computer choice: Scissors RESULT:...
Write a computer game based on rock-paper- scissors in C++. The 2-player game will be interactive: human vs. computer! Making the game interactive presents a new issue for us -- how do we get the computer's choice? To solve this, we will use a "random number generator", which is the basis for all computer gaming. This enables the properly programmed computer to act like it is actually "thinking" and making its own decisions. This is the largest, most involved program...
I'm trying to write this program in C++ and I'm having trouble initializing the overload function I have to use. Here's the assignment and what I got so far, thanks for the help! /*2. Implement the game of Rock-Paper-Scissors in C++, where you can play against the computer. a. Scissors beat paper, paper beats rock, and rock beats scissors. If both you and computer choose the same tool, it is a tie. b. Your program should have a class game...
For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-Oriented Programming. You will be working with me on a team to build the program. I have already written my part of the program, and the Game.java file is attached. Your task will be to write a RockPaperScissors class that contains the following methods: getUserChoice: Has the user choose Rock, Paper, or Scissors. After validating the input, the method returns a String containing the user choice....
Scissors bet par Paper beats rack Rock beats schoors Consider the game of rock-paper-scissors to be an experiment. In the long run, roommate A chooses rock 21% of the time, and roommate 3 chooses rock 61% of the time; roommate A selects paper 39% of the time, and roommate B selects paper 21% of the time; roommate A chooses scissors 40% of the time, and roommate B chooses scissors 18% of the time. (These choices are made randomly and independently...
Help needed in Perl language program!
Note : Perl Language
Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock paper scissors) is an extremely popular hand game most often played by children. Often, it is used as a method of selection similar to flipping a coin or throwing dice to randomly select a person for some purpose. Of course, this game is not truly random since a skilled player can often recognize and exploit the non-random behavior of...