1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
SashulF [63]
3 years ago
15

Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follo

ws:
a. 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.

b. 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.

c. After, a function, determineWinner, 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:

i. If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.)

ii. If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.)

iii. If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.) iv. If both players make the same choice, the game ends in a draw and there is no winner.

d. 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 in parts a – d.
Computers and Technology
1 answer:
kakasveta [241]3 years ago
7 0

A program that lets the user play the game of Rock, Paper, Scissors against the computer.

Explanation:

a. 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.

b. 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

c. After, a function, determineWinner, will determine the winner between the user’s choice vs. the computer’s choice.The result is selected according to the following rules:

d. 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.

#include <iostream>

#include <stdlib.h>

int main() {

srand (time(NULL));

int computer = rand() % 3 + 1;

int user = 0;

 std::string roc = "1) Rock\n";

 std::string pap = "2)Paper\n";

 std::string sci = "3) Scissors\n";

std::cout << "rock paper scissors!\n";

std::cout << roc;

std::cout << pap;

std::cout << sci;

std::cout << "Choose: ";

std::cin >> user;

std::cout << "\nYou  choose ";

 switch(user){

   case 1 :

    std::cout << roc;

    break;

   case 2 :

    std::cout << pap;

    break;

   case 3 :

    std::cout << sci;

    break;

   default :

    std::cout << "Invalid Option\n";

 }

std::cout << "Comp choose ";

   switch(computer){

   case 1 :

    std::cout << roc;

    break;

   case 2 :

    std::cout << pap;

    break;

   case 3 :

    std::cout << sci;

    break;

   default :

    std::cout << "Invalid Option\n";

 }

 if(user == computer){

   std::cout << "Draw Game\n";

 }

 else if(user == 1 && computer == 3){

   std::cout << "You Win\n";

 }

 else if(user == 3 && computer == 2){

   std::cout << "You Win\n";

 }

 else if(user == 2 && computer == 1){

   std::cout << "You Win\n";

 }

 else{

   std::cout << "Computer Wins!\n";

 }

}

You might be interested in
What can you do to improve your own digital wellness?
julsineya [31]
Update your passwords frequently, delete unused accounts, and be diligent about who and what you give your most personal information to. Invest in tech that fits your lifestyle without offering further distractions.
4 0
3 years ago
Read 2 more answers
Aiming high means???
Llana [10]

Answer:

in what context is it in? it could be aim high for goals set limits that are hard to reach but not impossible

Explanation:

5 0
3 years ago
I need help with my homework
lukranit [14]

Answer:

C is not equal to the other two.

Explanation:

A = 35

B = 35

C is actually equal to 36.

8 0
2 years ago
Any single girls 12-14 im a 13 yo boy idc if this aint a dating site
-BARSIC- [3]

Answer:

THIS AN'T DATING APP

Explanation:

THIS IS THE ONE THE ONLY

BRAINY

5 0
3 years ago
Read 2 more answers
Fill in the blanks:In the context of cyber security, social engineering (SE) is a deceptive practice that exploits human _______
lord [1]

Answer:

In the context of cyber security, social engineering (SE) is a deceptive practice that exploits human <u>weaknesses </u>  by inducing victims to interact with a digital device in a way that is not in their best interest. Many of these attacks begin with<u> spam</u> , which is defined as unsolicited messages that are usually sent in massive numbers using electronic mail systems. A spam  <u>filter</u> uses a set of rules to examine email messages and determine which are spam. There are four common types of spam filters.<u> Content  </u>filters examine the content within a message for certain words or phrases commonly used in spam emails.<u> Header</u> filters review the email header for falsified information, such as spoofed IP addresses. <u>Blacklist</u> filters block mail that originates from IP addresses of known spammers. <u>Permission </u>                    filters block or allow mail based on the sender's address. <u>Phishing</u> is an email scam that masquerades as a message from a(n) legitimate company or agency of authority, such as the IRS. <u>Pharming</u> redirects Web site traffic to fraudulent Web sites that distribute malware, collect personal data, sell counterfeit products, and perpetrate other scams. A rogue <u>antivirus </u>                exploit usually begins with a virus warning and an offer to disinfect the infected device. Some software is not exactly malware, but it is a nuisance. A <u>PUA </u>takes up residence on a digital device and seems impossible to disable or remove.

3 0
3 years ago
Other questions:
  • Which one of these is the most commonly used hardware interface for attaching peripherals to a microcomputer?
    8·1 answer
  • In a(n) __________ situation, a wireless device is configured to appear to be a legitimate access point, enabling the operator t
    14·1 answer
  • What is an example of a boolean operator?
    14·1 answer
  • Calculate the resistance of an unknown resistor in a circuit with 30 volts and 6 amps. The formula is R = V/I.
    6·1 answer
  • Pleasee help meeeeeeeeee I’m stuckk!!!!
    14·2 answers
  • Choose all items that represent examples of good website accessibility.
    8·2 answers
  • What does CPU stand for
    7·1 answer
  • What is the meaning of FTTH
    9·2 answers
  • Which term means a cryptography mechanism that hides secret communications within various forms of data?.
    6·1 answer
  • Which statement is true about biometrics as an authentication method?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!