i am having trouble with the fuctions: string getComputerChoice(string); string
ID: 3641508 • Letter: I
Question
i am having trouble with the fuctions: string getComputerChoice(string);string getPlayerChoice(string);
bool isTie(string, string);
bool isPlayerWinner(string, string);
heres my code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
string getComputerChoice(string);
string getPlayerChoice(string);
bool isTie(string, string);
bool isPlayerWinner(string, string);
int main()
{
char selection;
string computerchoice;
string playerchoice;
do
{
cout << "ROCK PAPER SCISSORS MENU ";
cout << "------------------------- ";
cout << "p) Play Game ";
cout << "q) Quit ";
cin >> selection;
if(selection == 'p')
{
getComputerChoice(computerchoice);
getPlayerChoice(playerchoice);
//here its not displaying what i and the computer chosed.
cout << "You choose: " << playerchoice << " ";
cout << "The computer chose: " << computerchoice << " ";
if(playerchoice == computerchoice)
{
bool Tie(string playchoice, string computerchoice);
// heres it not displaying what i and the computer chosed when it was a tie
cout << "You choose: " << playerchoice << " ";
cout << "The computer chose: " << computerchoice << " ";
cout << "It's a TIE!";
}
else if(playerchoice != computerchoice && true)
{ // here I am suppose its suppose to return true when the user wins
bool isPLayerWinner(string playerchoice, string computerchoice);
cout << "You choose: " << playerchoice;
cout << "The computer chose: " << computerchoice;
cout << "WIN!";
}
else if(playerchoice != computerchoice && false)
{
// here it suppose to return a false if the user loses.
bool isPlayerwinner(string playerchoice, string computerchoice);
cout << "You choose: " << playerchoice;
cout << "The computer chose: " << computerchoice;
cout << "sorry you lose.";
}
}
else if(selection == 'q')
{
cout << " you have quit the program";
}
}while(selection != 'q');
system("PAUSE");
return 0;
}
string getComputerChoice(string computerchoice)
{
//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 computerchoice;
}
string getPlayerChoice(string playerchoice )
{
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";
}
return playerchoice;
}
bool isTie (string playerchoice, string computerchoice)
{
if(playerchoice == computerchoice)
return false;
else
return true;
}
bool isPLayerWinner(string playerchoice, string computerchoice)
{
if(playerchoice == "Rock" && computerchoice == "Scissors")
{
return true;
}
else if(playerchoice == "Paper" && computerchoice == "Rock")
{
return true;
}
else if(playerchoice == "Scissors" && computerchoice == "Paper")
{
return true;
}
else
{
return false;
}
}