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]
3 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:
vekshin13 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
Show the steps of a Selection Sort for the numbers ( 5 3 9 5 ).
Sedbober [7]

Answer:

Sorted array will be:-

3 5 5 9

Explanation:

In Selection Sort algorithm it sorts the array by repeatedly finds the minimum in the array form the array that is unsorted and swaps it with the value at the first position.

The unsorted array:- 5 3 9 5

In first iteration

minimum is 3.

3 will be swapped with 5.

Now the array is 3 5 9 5

sorted array 3

In second iteration

unsorted array is 5 9 5

sorted array 3 5

and the minimum from it is 5

No swapping will occur.

In third iteration

unsorted array is 9 5

minimum is 5

sorted array 3 5 5

swap it with 9.

Now the array is sorted.

3 5 5 9

3 0
3 years ago
Driving is expensive. Write a program with two inputs, a car's miles/gallon and the cost of gas/gallon both represented as doubl
Nataly_w [17]

Answer:33

Explanation:

6 0
2 years ago
What color is excel?​
Eduardwww [97]

Answer:

green

Explanation:

5 0
2 years ago
Read 2 more answers
Match the column.<br> Description Shortcut key<br> Move to next cell in row page up
Musya8 [376]

The matchup are:

1) move to next cell in row - tab

2) move to previous cell in row - shift+tab

3) up one screen - page up

4) down one screen - page down

5) move to next worksheet - ctrl + page down

6) move to previous worksheet - ctrl + page up

7) go to first cell in data region - ctrl+ home

8) go to last cell in data region - ctrl + end

<h3>What are computer shortcut keys?</h3>

A computer shortcut is known to be some group of one or a lot of keys that brings about a command in software or in any kind of operating system.

Hence, The matchup are:

1) move to next cell in row - tab

2) move to previous cell in row - shift+tab

3) up one screen - page up

4) down one screen - page down

5) move to next worksheet - ctrl + page down

6) move to previous worksheet - ctrl + page up

7) go to first cell in data region - ctrl+ home

8) go to last cell in data region - ctrl + end

Learn more about computer shortcut from

brainly.com/question/12531147

#SPJ1

4 0
1 year ago
3. Find the best.
Tamiku [17]

Answer:

1. is the answer

Explanation:

<h2>mark me as brainlest</h2>

6 0
2 years ago
Other questions:
  • A. True
    14·2 answers
  • 6. Sandra did a survey to see how
    9·1 answer
  • What does the do not disturb button do on the iphone?
    12·1 answer
  • Is regular Facebook use healthy? Why or why not?
    10·2 answers
  • Refer to the color wheel to identify the color scheme.
    13·1 answer
  • Write a WHILE loop that lets the user enter a number.
    14·1 answer
  • When you open a browser window, it open in a _____. <br> a. fieldb. folderc. menud. window?
    7·1 answer
  • My serious question that needs answering pronto!!!
    11·1 answer
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • How many MB are there in 1000 KB?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!