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

Im having trouble understanding how to do functions thus im stuck on this homewo

ID: 3549826 • Letter: I

Question

Im having trouble understanding how to do functions thus im stuck on this homework assignment can someone help me out please?


The general game of Rock Paper Scissors works as follows (25 pts):

1.        First both players choose Rock, Paper or Scissors  (a player cannot see the other players choice until they have made their choice)

2.        Next a winner is determined based on the following rules (these are the ONLY ways you can win the game if you didnt win and you didnt tie you lost):

       If one player chooses Rock and the other player chooses Scissors, then Rock wins

o   The game then prints a message to the user indicating they won

       If one player chooses Scissors and the other player chooses Paper, then Scissors wins

o   The game then prints a message to the user indicating they won

       If one player chooses Paper and the other player chooses Rock, then Paper wins

o   The game then prints a message to the user indicating they won

       If both players make the same choice the result is a tie and the game will print a message saying the game was a tie

The program should begin by displaying the following menu:

ROCK PAPER SCISSORS MENU

-------------------------

p)Play Game

q)Quit

-If the user selects p:  

1.    First the program should call a function named getComputerChoice to get the computers choice in the game. The getComputerChoice function should generate a random number between 1 and 3.  If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has chosen Scissors.   (Hint:  one way to do this is to return an int from the function and make the function have no arguments).    This function is REQUIRED to be a value returning function (do NOT make a void function).

2.    Next the program should call a function named getPlayerChoice to get the users (players) choice in the game.  Have the users choice be represented by a number just like the computers was.  The getPlayerChoice function should display a menu similar to the one below and then get a 1, 2, or 3 as the users choice for Rock, Paper or Scissors.  Do not allow the user to enter an invalid choice they must enter 1, 2, or 3 (use integers for the menu on this instead of chars).  (Hint:  one way to implement this function is to return an int from the function and make the function have no arguments).  This function is REQUIRED to be a value returning function (do NOT make a void function).

Rock, Paper or Scissors?

1) Rock

2) Paper

3) Scissors

Please enter your choice:

3.    Next the program should display what the user chose and what the computer chose.  You will need to convert both the users and the computers integer choices of 1, 2, or 3 to the corresponding strings:  Rock, Paper, or Scissors.  The display should be similar to the following (in the example below the user chose 3 for Scissors and the computer chose 2 for Paper):

You chose: Scissors

The computer chose: Paper

4.    Next the program should call a function named isTie (Hint:  one way to do this is to have the function return a bool and take two arguments) to see if the game was a tie.  This function is REQUIRED to be a value returning function (do NOT make a void function).  The game is a tie if both the computer and user made the same choice. If the game was a tie display the appropriate message.  An example of a tie is shown below with the appropriate message on the third line.

You choose: Scissors

The computer chose: Scissors

It's a TIE!

5.    If the game was NOT a tie, the program should next determine if the player (user) has won the game.  You should use a function called isPlayerWinner to do this, the function should take two arguments (the player choice and the computer choice and return true if the player is a winner and false if the player is not a winner).  This function is REQUIRED to be a value returning function (do NOT make a void function).

    After calling the function, cased on the result of it, if the player has won the program should display a message similar to the one below telling the user they won. In the example below the users winning choice is Rock and the computers losing choice is Scissors. (Remember the rules for winning and losing are at the top of the page)

You choose: Rock

The computer chose: Scissors

You WIN!

6.    If the game was NOT a tie and the user (player) did NOT win this means the computer won and the program should display a message saying the user has lost.  In the example below the computers winning choice is Paper (the users losing choice is Rock).  Do not make this complicated, if it was not a tie and the player did not win the computer won.

                  

You choose: Rock

The computer chose: Paper

Sorry you LOSE.

     

-If the user selects q:   Quit the program

-If the user selects anything other than p or q:  Display an error message.

-The program should keep redisplaying the menu and let the user play as many games against the computer as they would like.  

Explanation / Answer

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

int getComputerChoice(string, string );
int getPlayerChoice(x, y );
string displaychoices(j, i);
bool Tie ( );
int isPlayerWinner();

int main()
{
char selection;
srand((unsigned)time(NULL));


do
{

cout << "ROCK PAPER SCISSORS MENU ";
cout << "------------------------- ";
cout << "p) Play Game ";
cout << "q) Quit ";
cin >> selection;



}while(selection != 'q');

return 0;
}


int getComputerChoice()
{

char selection;
string computerchoice;

int num;
num = rand() % 3 + 1;

if(num == 1)
{
computerchoice = "Rock";
}
else if (num == 2)
{
computerchoice = "Paper";
}
else if (num == 3)
{
computerchoice = "Scissors";
}

return 0;
}



int getPlayerChoice()
{
int selection;
string playerchoice;
cout << "Rock, Paper or Scissors ";
cout << "1) Rock ";
cout << "2) Paper ";
cout << "3) Scissors ";
cout << "PLease enter your choice:";
cin >> selection;

if(selection == 1)
{
playerchoice == "Rock";
}
else if(selection == 2)
{
playerchoice == "paper";
}
else if(selection == 3)
{
playerchoice == "Scissors";
}

}

string displaychoices( )
{
cout << "You choose: " << getPlayerChoice(playerchoice);
cout << "The computer chose: " << getComputerChoice(computerchoice);
}




bool Tie ()
{
if(playerchoice == computerchoice)
{
cout << "You choose: " << playerchoice;
cout << "The computer chose: " << computerchoice;
cout << "It's a TIE!";
}

}

int isPLayerWinner()
{
if(playerchoice != computerchoice)
{


cout << "You choose: " << playerchoice;
cout << "The computer chose: " << computerchoice;
cout << "WIN!";
}

else if
{
cout << "You choose: " << playerchoice;
cout << "The computer chose: " << computerchoice;
cout << "sorry you lose."