Question

This is a C++ question need to complete project 2. attached the completed simple version of...

This is a C++ question need to complete project 2. attached the completed simple version of the program below but need the updated version which is listed in the project 2 outline

Project 2

Rock, Paper, Scissors Updated

Take the solution to Lab 3 and make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch. Make sure the user knows why he/she has won or lost – print a message like “Paper covers Rock” or “Scissors cuts Paper”.

Ask the user how many times he/she wants to play and incorporate that into a for loop or allow the user to keep playing until he/she says to stop using a do-while loop.

Add the code to count how many wins, losses and ties that the user has and print the results at the end of the program before stopping the program.

Allow the user to exit a game, not the program, if he wants to – use a code of ‘X’. Also keep a count of exits from a game. Make sure your run has at least one exit.

Also have the program determine if a user did not type in R, P, S or X and print “Bad Code” and allow the user to continue the game. Run at least once with a “Bad Code”.

using namespace std;

#include <ctime>
#include <time.h>
#include <cstdlib>
#include <iostream>

int main()
{
//Declaration statements
srand(time(0));
char user, computer;
int comp=rand()%3+1;
if (comp==1)
   computer='R';
else if(comp==2)
   computer='P';
else computer='S';

//Input Statements
cout<<"Type in your choice (R,P,S) ";
cin>>user;
cout<<"user has picked "<<user<<endl;
cout<<"computer has choosen "<<computer<<endl;

//Output statements
if(user==computer)
cout<<"Tie"<<endl;

//else user rock
else if(user=='R')
   if (computer=='P')
       cout<<"computer-wins-Paper crushes Rock"<<endl;
   if (computer=='S')
       cout<<"you win-Rock crushes scissors"<<endl;
      
//else user scissors
else if(user=='S')
   if (computer=='P')
   cout<<"you win-Scissors cut paper"<<endl;
   if (computer=='R')
   cout<<"computer wins-Rock crushes scissors";

//else//user is paper
else if(user=='P')
   if (computer=='R')
        cout<<"you win-paper crushes Rock"<<endl;
    if (computer=='S')
        cout<<"you lose-Scissors cut paper"<<endl;

//Final statements

return 0;

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

Here is code:

using namespace std;

#include <ctime>

#include <time.h>

#include <cstdlib>

#include <iostream>

int main()

{

//Declaration statements

srand(time(0));

char user, computer;

int winCount = 0, loseCount = 0, tieCount = 0;

do

{

int comp = rand() % 3 + 1;

switch (comp)

{

case 1:

computer = 'R';

break;

case 2:

computer = 'P';

break;

case 3:

computer = 'S';

break;

}

//Input Statements

cout << "Type in your choice (R,P,S), X to Exit ";

cin >> user;

if (user == 'R' || user == 'P' || user == 'S' || user == 'X')

{

cout << "user has picked " << user << endl;

cout << "computer has choosen " << computer << endl;

//Output statements

if (user == computer)

{

cout << "Tie" << endl;

tieCount++;

}

//else user rock

else if (user == 'R')

{

if (computer == 'P')

{

cout << "computer-wins-Paper crushes Rock" << endl;

loseCount++;

}

if (computer == 'S')

{

cout << "you win-Rock crushes scissors" << endl;

winCount++;

}

}

//else user scissors

else if (user == 'S')

{

if (computer == 'P')

{

cout << "you win-Scissors cut paper" << endl;

winCount++;

}

if (computer == 'R')

{

cout << "computer wins-Rock crushes scissors" << endl;

loseCount++;

}

}

//else//user is paper

else if (user == 'P')

{

if (computer == 'R')

{

cout << "you win-paper crushes Rock" << endl;

winCount++;

}

if (computer == 'S')

{

cout << "you lose-Scissors cut paper" << endl;

loseCount++;

}

}

}

else

{

cout << "Bad Code" << endl;

}

} while (user != 'X');

cout << "Total wins : " << winCount << endl;

cout << "Total Lose : " << loseCount << endl;

cout << "Total tie : " << tieCount << endl;

//Final statements

return 0;

}

Output:

Type in your choice (R,P,S), X to Exit R user has picked R computer has choosen S you win-Rock crushes scissors Type in your

Add a comment
Know the answer?
Add Answer to:
This is a C++ question need to complete project 2. attached the completed simple version of...
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
  • Use Dev C++ for program and include all of the following. Im lost. Make sure the...

    Use Dev C++ for program and include all of the following. Im lost. Make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch. Make sure the user knows why he/she has won or lost – print a message like “Paper covers Rock” or “Scissors cuts Paper”. Ask the user how many times he/she wants to...

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

  • How to call a function in another function?C++ Project assistance. In the Project I am attempting...

    How to call a function in another function?C++ Project assistance. In the Project I am attempting to pass getOutcome into runGame to attempt to figure out who would win. Upon trying I get an error that getOutcome isn't in scop of runGame. The & symbols were my last attempt at trying to pass it, I do see it is wrong, and any help that can help me with just that is very appreciated. #include <iostream> #include <fstream> #include <string> #include...

  • (C++) Hey guys we just went over loops and it got me confused, it has me...

    (C++) Hey guys we just went over loops and it got me confused, it has me scrathcing my head for the past two days. I would appreciate any help you guys have to offer. Few places I have a hard time is get input and determine winner(cummulative part). Write a program that lets the user play the Rock, Paper, Scissors game against the computer. The computer first chooses randomly between rock, paper and scissors, but does not display its choice....

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

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

  • Write a program in the Codio programming environment that allows you to play the game of...

    Write a program in the Codio programming environment that allows you to play the game of Rock / Paper / Scissors against the computer. Within the Codio starting project you will find starter code as well as tests to run at each stage. There are three stages to the program, as illustrated below. You must pass the tests at each stage before continuing in to the next stage.  We may rerun all tests within Codio before grading your program. Please see...

  • In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user...

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

  • Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that...

    Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program...

  • In java language here is my code so far! i only need help with the extra...

    In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...

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