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
STALIN [3.7K]
2 years ago
5

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

ws. 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 breaks the scissors.) • If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.) • If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.) • If 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 the code and the console output from running your program with test inputs in your report.
Computers and Technology
1 answer:
vekshin12 years ago
3 0

#include <iostream>

#include <ctime>

#include <conio.h>

using namespace std;

bool player_won (int player, int computer)

{

   switch (player)

   {

   case 1:

       if (computer==2)

           return false;

       else return true;

   case 2:

       if (computer==3)

           return false;

       else return true;

   case 3:

       if (computer==1)

           return false;

       else return true;

   }

}

main ()

{

   cout<<"Rock, paper scissors by TheMaster999"<<endl;

   srand (time(NULL));

   while (true)

   {

       int computer=rand()%3+1;

       int player;

       cout<<"If u choose rock type 1, if u choose paper type 2, if u choose scissors type 3"<<endl;

       cin>>player;

       if (player==computer)

           cout<<"Draw, play again"<<endl;

       else if (player_won(player,computer))

       {

           cout<<"Congratulations, you won!"<<endl;

           break;

       }

       else

       {

           cout<<"You lost :("<<endl;

           break;

       }

   }

   cout<<"Thank you, for playing my game"<<endl;

   getch();

   return 0;

}

You might be interested in
Carbon monoxide poisoning can result from breathing
Mamont248 [21]
The answer is the letter a
6 0
3 years ago
Identify 3 ways mobile phone could be used to contact a bank apart from making a phone call to the bank
Zepler [3.9K]

Answer:

1. Email

2. Website

3. Customer service

8 0
3 years ago
Which of the following rules should be used to keep the appropriate distance between your vehicle and the vehicle in front of yo
S_A_V [24]
I would say two car length rule. I am not sure what the official license rule is or if it has been changed, but originally the rule was 3 seconds usually depending on how fast the car is going. The faster you are going, the longer it takes to stop. So two-car length rule would probably be the best choice. Definitely not A.
8 0
3 years ago
Read 2 more answers
Which extension is appropriate for Word document templates?
expeople1 [14]
The answer to this question is A
8 0
2 years ago
Read 2 more answers
Hey guys, I am new here but I keep getting questions that are too hard for me and I already set my grade level, what else can I
zysi [14]

Answer:

I don't know, Brainly says im an expert but i dont think so

4 0
3 years ago
Other questions:
  • A student is helping a friend with a home computer that can no longer access the Internet. Upon investigation, the student disco
    9·1 answer
  • 1. Describe your Microsoft word skills that need to be improved upon the most. 2. Explain the Microsoft word skills you are most
    12·1 answer
  • GAMES Which is better Roblox or BattleCamp Basically Free Points But Please Answer
    7·2 answers
  • Universal Containers (UC) has decided to build a new, highly sensitive application on the Force platform. The security team at U
    11·1 answer
  • Individuals who require better speed and performance for graphics-intensive applications (e.g., video editing, gaming, etc.) pre
    8·1 answer
  • What concept or principle requires layered, complementary controls sufficient to detect and deter infiltration and exploitation
    6·1 answer
  • Based on the screenshot below which letter do you select to sort the items in an alphabetical order?
    9·1 answer
  • Consider the code below. When you run this program, what is the output if the temperature is 77.3 degrees Fahrenheit?
    6·1 answer
  • The function of anOR gate can best be described as a gate which provides an output of 1 only when
    10·1 answer
  • What is computer science​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!