Please give me The Flow Charts of this program. // Write a program that lets the
ID: 3838623 • Letter: P
Question
Please give me The Flow Charts of this program.
// Write a program that lets the user play the game of Rock, Paper, Scissors against the computer.
//The program should work as follows. 1. 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.) 2.
//The user enters his or her choice of "rock "paper or "scissors" at the keyboard. (You can use a menu if you prefer. 3.
//The computer's choice is displayed. 4. A winner 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.)
//lf one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.) lf both players make the same choice,
//the game must be played again to determine the winner. Be sure to divide the program into functions that perform each major task.
//
#include
#include
using namespace std;
// Get the corresponding string choice
string getStringChoice(int i)
{
string choice[] = { "Rock", "Paper", "Scissors" };
return choice[i - 1];
}
// Displays the menu
void menu()
{
cout << " Game Menu" << endl;
cout << " ---------" << endl;
cout << " 1) Rock" << endl;
cout << "2) Paper" << endl;
cout << "3) Scissors" << endl;
cout << "4) Quit" << endl;
}
// Returns the result of the game
// -1 if player wins
// 1 if computer wins
// 0 if tie
int getReult(int playerChoice, int compChoice)
{
int result = -1;
if (playerChoice == compChoice)
{
return 0;
}
else if (playerChoice == 1) // Rock
{
if (compChoice == 2) // Paper
result = 1;
else if (compChoice == 3) // Scissors
result = -1;
}
else if (playerChoice == 2) // Paper
{
if (compChoice == 1) // Rock
result = -1;
else if (compChoice == 3) // Scissors
result = 1;
}
else if (playerChoice == 3) // Scissors
{
if (compChoice == 1) // Rock
result = 1;
else if (compChoice == 2) // Paper
result = -1;
}
return result;
}
int main()
{
srand((NULL));
int playerChoice = 0;
do
{
// Get computer's choice
int compChoice = (rand() % 3) + 1;
// Display menu
menu();
// Get player's choice
playerChoice = 0;
while ((playerChoice < 1) || (playerChoice > 4))
{
cout << "Enter your choice: ";
cin >> playerChoice;
}
if (playerChoice != 4)
{
// Display player's anad computer's choice
cout << "You selected: " << getStringChoice(playerChoice) << endl;
cout << "The computer selected: " << getStringChoice(compChoice) << endl;
// Get result
int result = getReult(playerChoice, compChoice);
// Display result
if (result == 0) // Tie
{
cout << "Tie. No winner." << endl;
}
else if (result == -1) // Player wins
{
cout << "You win." << endl;
}
else if (result == 1) // Computer wins
{
cout << "Computer wins." << endl;
}
}
} while (playerChoice != 4);
}
Explanation / Answer
Hi I uploaded image in Google drive and share a link below...
Pls refer it for answer
https://drive.google.com/file/d/0B-x1giaUCupZd2NnejJCcjVob1E/view?usp=drivesdk