Question

Write a computer game based on rock-paper- scissors in C++. The 2-player game will be interactive:...

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 we have yet written. It will require careful step-by- step
development. You will be lead through this one in a series of steps, in an effort to train you in the
software development process.
In the coding for this game you will use code blocks, loops, and if and/or switch structures.
Organizing code into "code blocks" will prepare you for moving code blocks into subprograms in
coming labs.
The game will replay until the human player decides to quit. Human input will be through the
keyboard, entering R for rock, P for paper, S for scissors, or Q to quit. Computer input will be
randomly generated. Here is sample output for the game, with the input prompt in blue, the human
response in red, and the results in green:
Choose: [Rock,Paper,Scissors,Quit]: p
Computer:S, Human:P, Computer wins
Choose: [Rock,Paper,Scissors,Quit]: p
Computer:P, Human:P, tie
Choose: [Rock,Paper,Scissors,Quit]: p
Computer:R, Human:P, Human wins
Choose: [Rock,Paper,Scissors,Quit]: p
Computer:S, Human:P, Computer wins
Choose: [Rock,Paper,Scissors,Quit]: x
Choose: [Rock,Paper,Scissors,Quit]: p
Computer:S, Human:P, Computer wins
Choose: [Rock,Paper,Scissors,Quit]: q
Do not color code your I/O!

Use only techniques taught in this class. Do NOT use regular expressions. Do NOT use arrays. Do
NOT use subprograms. Do NOT use pointers. These are great programming tools, but we have not
covered them.

1 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<time.h> //needed for seeding rand
#include<stdlib.h>//contains srand,rand()
using namespace std;
int main()
{ int choice;
srand (time(NULL)); //initialze random seed
int comp=rand()%3+1;//generates a random no. between 1,2 & 3 and assigns it to Computer
char player='a'; //storing choice of player
while(player!='q'&&player!='Q')
{
cout<<"Choose: [Rock,Paper,Scissors,Quit]:";
cin>>player;
  
  
if(player=='r' || player=='R') //converting player move to equivalent number
{ //rock=1,paper=2,scissors=3
choice=1;
cout<<" Human:R, ";
}
else if(player=='p'||player=='P')
{
choice=2;
cout<<" Human:P ";
}
else if(player=='s'||player=='S')
{
choice=3;
cout<<" Human:S ";
}
else
continue;
//finding result
if(comp==1)
cout<<"Computer:R,";
if(comp==2)
cout<<"Computer:P,";
if(comp==3)
cout<<"Computer:S,";
if(choice==4)
  
if(comp==1&&choice==3)
cout<<"Computer wins\n";
if(comp==1&choice==2)
cout<<"Human wins\n";
if(comp==2&&choice==1)
cout<<"Computer wins\n";
if(comp==2&&choice==3)
cout<<"Human wins\n";
if(comp==3&&choice==1)
cout<<"Human win\n";
if(comp==3&&choice==2)
cout<<"Computer wins\n";
if(comp==choice)
cout<<"tie\n";
  
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a computer game based on rock-paper- scissors in C++. The 2-player game will be interactive:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This program should be in c++. Rock Paper Scissors: This game is played by children and...

    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...

  • Rock, Paper, Scissors - Write a MATLAB script file to play Rock, Paper, Scissors with the...

    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:...

  • Create a python program to play rock paper scissors using a while loop and if statements....

    Create a python program to play rock paper scissors using a while loop and if statements. I have started but have gotten stuck in a continuous loop. Please look over my code and help me find where I went wrong. Here it is: import random #Choice weapons=['Rock' ,'Paper' ,'Scissors'] print('Rock, Paper, Scissors!') print('Rock, Paper, Scissors!') print('Shoot!') human=input('Choose Rock, Paper, Scissors, or Quit! ') print('')#Blank Line while human != 'Quit': human_choice=human computer=random.choice(weapons) print(computer) if human==computer: print("It's a tie!") elif human=='Rock': if...

  • Objective: Write a program that simulates a game of rock, paper, scissors between a human and...

    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...

  • java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    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...

    (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...

  • Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock p...

    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...

  • Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

    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...

  • C++ You are asked to implement scissors-rock-paper game where the players are a computer and a...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT