Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Electrical & Electronics Expert

Rock, Paper, Scissors
Description:
To expand further, we want to try out logic in interacting with users. Here is a sample of a game, using loops and decisions to allow a person to play rock-paper-scissors with a computer.
Pseudocode
We have a helper function that we will use here that tells us who won. It will result in +1 if the player wins, a -1 if the computer wins, and a 0 if it is a tie.
function compareOutcome(computerMove: Integer, 
playerChoice : Integer) returns Integer
And the main flow of our logic is as such.
while (true)
Integer : computerChoice = randomChooser()
Integer : playerEntry = prompt user to enter a value
If (playerEntry is not a valid input)
Prompt user they have picked a bad number and try again
Else
Integer : outcome = compareOutcome(computerMove, playerEntry)
If (outcome = 0)
Prompt user it is a tie, and try again
Else if (outcome = -1)
Prompt user they lost
Break out of loop
Else
Prompt user they won
Break out of loop
End if
End if
end loop
Flowchart


Note: In this case, note the advantages and disadvantages of flowcharts and pseudocode. The flowchart is easy to follow the logic for one scenario, but does it make it easier or harder to understand the code as a whole? There is no strict answer, but one that tells you a bit about your way of thinking and personal preference.
Interaction Scenario
For either of the solutions above, follow the logic and map out your interaction step-by-step, trying to exercise all paths of the logic. You will have to take at least 2 times through the game to map all scenarios.
Scenario 1
Step User Input System Response
1 User chooses 50 System says lower
2 ... ..


Scenario 2
Step User Input System Response





(copy and add more if needed/desired)
Number Guessing Game
Description
Now it is your turn to try out user interaction with a simple game. This goes back to the number guessing game. The user will input a number each time, say between 1 and 100. The computer will randomly select 1 number each game (note this is different than the example above where it selects a new answer each round), and the game continues until the user guesses the right number. 
Like above, your solution should accommodate for invalid input, but do not worry about how to make that logic work for now. Your solution should give some hints though if the guess the user made was too high or too low, to help them on their way.
Flowchart

Pseudocodeour solution here> 

Electrical & Electronics, Engineering

  • Category:- Electrical & Electronics
  • Reference No.:- M91627994

Have any Question?


Related Questions in Electrical & Electronics

Problems -problem 1 - find v0 in the op amp circuit of fig

Problems - Problem 1 - Find v 0 in the op amp circuit of Fig. 1. Problem 2 - Compute i 0 (t) in the op amp circuit in Fig. 2 if v s = 4 cos(10 4 t). Problem 3 - If the input impedance is defined as Z in = v s /I s , find ...

Problem 1 a two-phase servomotor has rated voltage applied

Problem 1: A two-phase servomotor has rated voltage applied to its excitation winding. The torque speed characteristic of the motor with Vc = 220 V, 60 Hz applied to its control phase winding is shown in Fig.1. The momen ...

Assignment - power distribution system transformerscomplete

Assignment - Power Distribution System Transformers Complete your calculations, drawings, and answers, neatly handwritten on these sheets and hand in at the start of lecture in week 6. Absolutely no late submissions will ...

Problem 1given a sequence xn for 0lenle3 where x0 1 x1 1

Problem # 1: Given a sequence x(n) for 0≤n≤3, where x(0) = 1, x(1) = 1, x(2) = -1, and x(3) = 0, compute its DFT X(k). (Use DFT formula, don't use MATLAB function) Problem # 2: Use inverse DFT and apply it on the Fourier ...

Question -i a star-connected three-phase synchronous

Question - (i) A star-connected, three-phase synchronous induction motor takes a current of 10 amps from a 415 volt supply at unity power factor when supplying a steady load. If the synchronous reactance is 5 ohms/phase ...

Questions -problem 1 - determine the laplace transform ofa

Questions - Problem 1 - Determine the Laplace transform of: (a) cos(ωt + θ) (b) sin(ωt + θ) Problem 2 - Obtain the Laplace transform of each of the following functions: (a) e -2t cos(3t)u(t) (b) e -2t sin(4t)u(t) (c) e - ...

Questions -problem 1 - a series rlc network has r 2 komega

Questions - Problem 1 - A series RLC network has R = 2 kΩ, L = 40 mH and C = 1μF. Calculate the impedance at resonance and at one-fourth, one-half, twice, and four times the resonant frequency. Problem 2 - Design a serie ...

1 a name the three major groups of contamination and

1. (a) Name the three major groups of contamination and briefly describe their physical characteristics. (b) Where do the above contamination types come from? Give one example of each. 2. Name two processes metrics which ...

Assignment -problem 1 -a consider the simplified dc system

Assignment - Problem 1 - a) Consider the simplified dc system shown in Fig. 1. Only one converter is modeled, with the remote end represented by a dc source. The ac system is rated at 345 kV, with the converter transform ...

Discuss the role of load factor on the cost of electrical

Discuss the role of load factor on the cost of electrical energy.

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As