The purpose of this assignment is for the student to get practice working with e
ID: 664320 • Letter: T
Question
The purpose of this assignment is for the student to get practice working with enums, functions, structs and 2 dimensional arrays. What To Do You will write a C++ program that plays the child's game rock/paper/scissors. The general rules of the game are as follows. Two players simultaneously pick 'rock', 'paper and 'scissors'. If both players choose the same thing, it is a tie. Choosing 'rock' beats 'scissors' but loses to 'paper. Choosing paper beats 'rock' but loses to 'scissors'. Choosing 'scissors' beats paper but loses to 'rock'. The program will do the following: 1. Ask the user for a name. 2. Generate a move for the computer using random numbers 3. Ask the user for a choice. Check to make sure they enter a valid response 4. Determine the winner. Keep track of both the human's and the computer's wins, losses and ties. 5. Ask the user if they want to continue. if not, print out statistics and exit program. See example below for more details. Some Hints on Implementation See the guessing game demo for an example of using random numbers. Use rand ( ) as this will give values between O and 2. % 3 For choices, use 0,1 and 2. These can easily be type casted to an enum type representing ROCK, PAPER and SCISSORS. To determine a winner, a good way to do this is to generate a table of winners for each pair of possible choices.Explanation / Answer
this questions has lot of subparts. Please post 1 more question.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string>
using namespace std;
int main()
{
do
{
std::string userChoice;
int computer;
string name;
cout << "+++ Rock Paper Scissors Game +++" << endl;
cout << "You will be playing our computer today"<<endl;
cout << "What is your name";
cin >> name;
cout << " " << endl;
cout << "0 - Rock 1- Paper, 2 - Scissors"<<endl;
cout <<"Your Choice"<<endl;
cin >> userChoice;
cout << "You entered: " << userChoice << endl;
cout << " " << endl;
srand(time(NULL));
computer = rand() % 10 + 1;
//Computer "brain"
if (computer <= 3)
{
cout << "Computer chose: Rock" << endl;
cout << " " << endl;
}
else if (computer <= 6)
{
cout << "Computer chose: Paper" << endl;
cout << " " << endl;
}
else if (computer >= 7)
{
cout << "Computer chose: Scissors" << endl;
cout << " " << endl;
}
//Determines winner
//Rock
if (userChoice == "rock" && computer <= 3)
{
cout << "It's a tie!" << endl;
cout << " " << endl;
}
else if (userChoice == "rock" && computer <= 6)
{
cout << "You lose!" << endl;
cout << " " << endl;
}
else if (userChoice == "rock" && computer >= 7)
{
cout << "You win!" << endl;
cout << " " << endl;
}
//Paper
if (userChoice == "paper" && computer <= 3)
{
cout << "You win!" << endl;
cout << " " << endl;
}
else if (userChoice == "paper" && computer <= 6)
{
cout << "It's a tie!" << endl;
cout << " " << endl;
}
else if (userChoice == "paper" && computer >= 7)
{
cout << "You lose!" << endl;
cout << " " << endl;
}
//Scissors
if (userChoice == "scissors" && computer <= 3)
{
cout << "You lose!" << endl;
cout << " " << endl;
}
else if (userChoice == "scissors" && computer <= 6)
{
cout << "You win!" << endl;
cout << " " << endl;
}
else if (userChoice == "scissors" && computer >= 7)
{
cout << "It's a tie!" << endl;
cout << " " << endl;
}
} while (cin.get());
cin.get();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.