Question

Use Dev C++ for program and include all of the following. Im lost.

Objectives: To use If-Statements to affect the logical flow of your program To use Switch Statements *lo design a game and ha

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

Heres what I have so far:

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
   char user, computer = ' ';
   int ComputerChoice= rand() % 3;

   srand(time(0));


   //Input Statements
   cout << "Enter your choice Rock(R), Paper(P), or Scissors(S): ";
   cin >> user;

   switch(ComputerChoice)
   {case 0:
       computer = 'R' ;
   case 1:
       computer = 'S' ;
   case 2:
       computer = 'P' ;
   }

  
  
   //Output Statements
if(user == computer)
   {cout << "Its a tie!" << endl;}
      
       else if(user == 'R' )
           {if(computer == 'S' )
           cout << "Rock crushes Scissors. User wins!" << endl;
               else
               cout << "Paper covers Rock. Computer wins!" << endl;}
  
       else if(user == 'S' )
           {if(computer == 'R')  
           cout << "Rock crushes Scissors. Computer wins!" << endl;
               else
               cout << "Scissors cuts Paper. User wins!" << endl;}
      
       else if(user == 'P' )
           {if(computer == 'R' )
           cout << "Paper covers Rock. User wins!" << endl;
               else
               cout << "Scissors cuts Paper. Computer wins!" << endl;}
  

   return 0;

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

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cctype>
using namespace std;
// Function Declaration
int computerPicks();
char getUserChoice(int &exits);
char displayComputerChoice(int comp);
void playGame(char userchoice, char computerchoice,int &wins,int &losses,int &ties);
int main()
{
// Declarig the variables
char userchoice, computerchoice, ch;
string winner;
int wins=0,losses=0,ties=0,exits=0;
srand ((unsigned)time(0));
while (true)
{
userchoice = getUserChoice(exits);
if(userchoice!='X')
       {
   // Calling the function
int comp = computerPicks();
computerchoice = displayComputerChoice(comp);
playGame(userchoice, computerchoice,wins,losses,ties);      
       }
  
    cout << "\nDo you Want to play again(Y/N) ?";
cin >> ch;

if (ch == 'y' || ch == 'Y')
{

continue;
}
else
{
   cout<<"No of Wins :"<<wins<<endl;
   cout<<"No of Losses :"<<losses<<endl;
   cout<<"No of Ties :"<<ties<<endl;
   cout<<"No of Exits :"<<exits<<endl;
break;
}
     
  
}

return 0;
}
/* Function implementation which
* randomly picks the computer's choice
*/
int computerPicks()
{
int computerchoice;

// Computer randomly picking number(either 0 or 1 or 2)
computerchoice = (rand() % (3));

return computerchoice;
}
// This function will get the computer choice
char displayComputerChoice(int comp)
{
char computerchoice;
// Getting the computer choice
if (comp == 0)
computerchoice = 'R';
else if (comp == 1)
computerchoice = 'P';
else if (comp = 2)
computerchoice = 'S';

/* based on the computer choice
* the corresponding case will get executed
*/
switch (computerchoice)
{
case 'R':
cout << "Computer Picks Rock" << endl;
break;
case 'P':
cout << "Computer Picks Paper" << endl;
break;
case 'S':
cout << "Computer Picks Scissors" << endl;
break;
}
return computerchoice;
}

// This function will get the valid user choice entered by the user
char getUserChoice(int &exits)
{
char userchoice;
/* This loop continues to execute until user
* enter valid number(either 'R' or 'P' or 'S' or 'Q')
*/
while (true)
{
// Getting the users choice
cout << "Enter 'R'= Rock , 'P'=Paper , 'S'=Scissors , 'X'= Exit :";
cin >> userchoice;

// Based on the users choice the corresponding case will get executed
switch (userchoice)
{
case 'R':
case 'r':
{
cout << "\nPlayer Picks Rock" << endl;
break;
}

case 'P':
case 'p':
{
cout << "\nPlayer Picks Paper" << endl;
break;
}
case 'S':
case 's':
{
cout << "\nPlayer Picks Scissors" << endl;
break;
}
case 'x':
case 'X':
{
   cout<<"** Game Exit **"<<endl;
exits++;
break;
}

default:
{
cout << "\nBad-Code." << endl;
continue;
}
}
break;
}
  
if(islower(userchoice))
userchoice=userchoice-32;

return userchoice;
}

// This function will start the game between player and computer
void playGame(char userchoice, char computerchoice,int &wins,int &losses,int &ties)
{
// Declaring variables
char rock = 'R', paper = 'P', scissors = 'S';
string winner;
/* Based on user and computer selected numbers
* the corresponding block will get executed
*/
if (userchoice == rock && computerchoice == scissors)
{
   cout<<"Rock smashes Scissors"<<endl;
winner = ":: Player Wins ::";
wins++;
}
else if (userchoice == scissors && computerchoice == rock)
{
   cout<<"Rock smashes Scissors"<<endl;
winner = ":: Computer Wins ::";
losses++;
}
else if (userchoice == rock && computerchoice == paper)
{
   cout<<"Paper covers Rock"<<endl;
winner = ":: Computer Wins ::";
losses++;
}
else if (userchoice == paper && computerchoice == rock)
{
   cout<<"Paper covers Rock"<<endl;
winner = ":: Player Wins ::";
wins++;
}
else if (userchoice == paper && computerchoice == scissors)
{
   cout<<"Scissors cuts Paper"<<endl;
winner = ":: Computer Wins ::";
losses++;
}
else if (userchoice == scissors && computerchoice == paper)
{
   cout<<"Scissors cuts Paper"<<endl;
winner = ":: Player Wins ::";
wins++;
}
else
{
winner = ":: Draw ::";
ties++;
}

// Displaying the Result.
cout << winner << endl;
}

___________________________

Output:

C:Program Files (x86)\Dev-CppMinGW64 bin\RockPaperScissorsRPSX.exe Enter ,R= Rock , P Paper. S-Scissors. X, = Exit :R P

_______________Thank You

Add a comment
Know the answer?
Add Answer to:
Use Dev C++ for program and include all of the following. Im lost. Make sure the...
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 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....

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

  • i have created a program for a game of rock, paper, scissors but i must make...

    i have created a program for a game of rock, paper, scissors but i must make it run more than once in some kind of loop. i want to add a function named runGame that will control the flow of a single game. The main function will be used to determine which game mode to initiate or exit program in Player vs. Computer, the user will be asked to enter their name and specify the number of rounds for this...

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

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

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

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

  • please help me fix this. I'm getting it all mixed up in user defined functions. here's...

    please help me fix this. I'm getting it all mixed up in user defined functions. here's the question. This week we'll write a C program that lets the user play the game of Rock, Paper, Scissors against the computer. Your program will call a user-defined function named display_rules that displays the rules of the game. It then proceeds to play the game. To determine the winner, your program will call another user- defined function called determine_winner that takes two integer...

  • Python please. I have a working one that doesn't keep track of w/l ratio, it may...

    Python please. I have a working one that doesn't keep track of w/l ratio, it may be helpful to see how others did the entire program and inserted that module. Write a modular program that let 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 thru 3 is generated but do not display the computer choice immediately. Number 1...

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

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