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
Njdnkjsdnjvnsdjvnjsdnvjsdvnjdnvjdsnvnksn
adoni [48]

Answer:

yes

Explanation:

7 0
2 years ago
How can you enter Task Manager in Windows? Select 3 options. press Ctrl + Shift + Tab press Ctrl+Alt+Delete and then click Task
Sophie [7]

Answer:

Please find the 3 options below.

Explanation:

To begin with, Task Manager in windows, is a monitor program that provides information or shows application and processes running on a computer. Task manager also provide insights about the general status of a computer. The three options for entering or accessing task manager in windows are:

1. Press Ctrl+Alt+Delete and then click Task Manager

2. Right-click the taskbar and choose Start Task Manager

3. Right-click the taskbar and choose Manage Tasks

5 0
3 years ago
Write a function listLengthOfAllWords which takes in an array of words (strings), and returns an array of numbers representing t
vesna_86 [32]

Answer:

   public static int[] listLengthOfAllWords(String [] wordArray){

       int[] intArray = new int[wordArray.length];

       for (int i=0; i<intArray.length; i++){

           int lenOfWord = wordArray[i].length();

           intArray[i]=lenOfWord;

       }

       return intArray;

   }

Explanation:

  1. Declare the method to return an array of ints and accept an array of string as a parameter
  2. within the method declare an array of integers with same length as the string array received as a parameter.
  3. Iterate using for loop over the array of string and extract the length of each word using this statement  int lenOfWord = wordArray[i].length();
  4. Assign the length of each word in the String array to the new Integer array with this statement intArray[i]=lenOfWord;
  5. Return the Integer Array

A Complete Java program with a call to the method is given below

<em>import java.util.Arrays;</em>

<em>import java.util.Scanner;</em>

<em>public class ANot {</em>

<em>    public static void main(String[] args) {</em>

<em>       String []wordArray = {"John", "James", "David", "Peter", "Davidson"};</em>

<em>        System.out.println(Arrays.toString(listLengthOfAllWords(wordArray)));</em>

<em>        }</em>

<em>    public static int[] listLengthOfAllWords(String [] wordArray){</em>

<em>        int[] intArray = new int[wordArray.length];</em>

<em>        for (int i=0; i<wordArray.length; i++){</em>

<em>            int lenOfWord = wordArray[i].length();</em>

<em>            intArray[i]=lenOfWord;</em>

<em>        }</em>

<em>        return intArray;</em>

<em>    }</em>

<em>}</em>

This program gives the following array as output: [4, 5, 5, 5, 8]

7 0
3 years ago
Digital manufacturing has impacted our world today! List a reasons why.
Maru [420]
Because we can get manufacturing faster than usual
6 0
3 years ago
Use the drop-down menus to complete the steps to share a presentation through OneDrive.
charle [14.2K]

Answer:

Share

OneDrive

In real time

Send

Explanation:

5 0
3 years ago
Other questions:
  • 2- There are many different design parameters that are important to a cache’s overall performance. Below are listed parameters f
    11·1 answer
  • What key combination in excel takes you back to the first cell
    7·1 answer
  • Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "To
    9·1 answer
  • If you want to learn more about a command, point to its button and wait for the ____ to appear.
    13·1 answer
  • What is f(-3) for the function f(a)=-2a2-5a+4?​
    10·1 answer
  • List 5 anti-virus products currently in use
    15·1 answer
  • What happens if you have you an image that has 6 bits-per-pixel and you change it to 12
    6·1 answer
  • 1. Pasar los siguientes ejercicios a diagrama de bloque
    11·1 answer
  • Using a third-party package of your choice, write a program that reads the contents of a csv file and saves it to an Excel file.
    10·1 answer
  • Edhesive 9.3 code practice
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!