Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that lets the user play the game of Rock, Paper, Scissors agains

ID: 3874942 • Letter: W

Question

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, the user enters his or her choice of “rock”, “paper”, or “scissors” at the keyboard using a menu in a function, userChoice, that returns a character. Next, there should be a function, computerChoice, that generates the computer’s play. A random number in the range of 1 through 3 is generated. (NOTE: You’ll have to do some research on how to create random numbers correctly.) 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. The computer’s choice is returned as a character. After, a function, determine Winner, will determine the winner between the user’s choice vs. the computer’s choice. (NOTE: It will return nothing, but it will take in the user’s choice and the computer’s choice as the two arguments.) The result is selected according to the following rules: If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.) If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.) If both players make the same choice, the game ends in a draw and there is no winner. Finally, after a result is selected, there should be a function, playAgain, in which the player should have the option of playing again. This should return a boolean. Be sure that the program contains at least the four functions mentioned . Write this code in c++.

Explanation / Answer

C++ program:   

#include <iostream>

#include <cmath>
#include <time.h>
#include <cstdlib>
using namespace std;

int main(){

  
char ch;
int win = 0;
int tie = 0;
int lose = 0;
  
do{
int choice;
cout << "--------------------------------------" << endl;
cout << "-- Lets play Rock, Paper, Scissors! --" << endl;
cout << "--------------------------------------" << endl;
cout << "Press 1 for Rock, 2 for Paper, 3 for Scissors:" << endl;
cin >> choice;
  
int ai = rand() % 3 + 1;
cout << "The computer chose: " << ai << endl;
  
if(choice == 1 && ai == 1){
cout << "Rock meets Rock its a tie!" << endl;
tie++;
}
else if(choice ==1 && ai== 2){
cout << "Rock is covered by Paper the computer wins!." << endl;
lose++;
}
else if(choice == 1 && ai == 3){
cout << "Rock crushes Scissors you win!" << endl;
win++;
}
else if(choice == 2 && ai == 1){
cout << "Paper covers Rock you win!" << endl;
win++;
}
else if(choice == 2 && ai == 2){
cout << "Paper meets Paper its a tie!" << endl;
tie++;
}
else if(choice == 2 && ai == 3){
cout << "Paper is cut by Scissors the computer wins!" << endl;
lose++;
}
else if( choice == 3 && ai == 1){
cout << "Scissors are crushed by Rock computer wins!" << endl;
lose++;
}
else if( choice == 3 && ai == 2){
cout << "Scissors cuts Paper you win!" << endl;
win++;
}
else if(choice == 3 && ai == 3){
cout << "Scissors meet Scissors its a tie!" << endl;
tie++;
}
  
else{
cout << "You didn't select 1, 2, or 3" << endl;
}

cout << "Wins: " << win << endl;
cout << "Ties:" << tie << endl;
cout << "Losses:" << lose << endl;
cout << "Would you like to play again? Y/N" << endl;
cin >> ch;
system("CLS");
}while(ch == 'Y' || ch == 'y');
return 0;
}

Algorithmic sequence:

1)starting main function.

2)initialize all required variables.

3)set the char variable for the y/n while loop.

4)set up my variables for the scores(ie. for win,lose,tie).

5)start of game loop, the loop will run untill ch == n.

6)Ask the player to choose Rock, Paper, Scissors.

7)Gets a random number between 1 and 3 and tell the player what was chosen by computer.

8)Starts possible outcome sequence in rock paper scissors there are 9 possible out comes 3 wins 3 ties and 3 losses.

9)Displays your score so far and asks if you want to play again then clears screen.

10)closing main.

In code:

--> Hitting any alphabet character when it asks for 1 2 or 3 will instantly close the program.

-->Same happens when you enter any alphabet character except y when it asks you if you would like to play again.

-->

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote