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

  • Write an algorithm C++ Rock, Paper, Scissors Updated Take the solution to Lab 3 and make...

    Write an algorithm C++ 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...

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

  • C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats...

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

  • JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There...

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

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

  • I'm trying to write this program in C++ and I'm having trouble initializing the overload function...

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

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