There are nine possible combinations of human play and computer play, all different, so there's no easy way to program them all in a small number of lines of code. Later, in Java, you can do things with table lookup, but for now you just need to trudge your way through them, like I did with the synchronization lines. Did you do that?
Being good at math is not necessary to be a good programmer, but it helps to know the basics. Did they teach you different number systems in grade school? They didn't do that when I went to school, but by the time I got to grad school they were teaching it to third and fourth graders. I don't know about your school.
The simple (and most tedious) way to do the scoring is brute force:
if comPlay=0 then if humPlay = "R" then print "tie"or else:
if (comPlay=1) and (humPlay = "P") then print "tie"or maybe even:
if (comPlay concatenate humPlay) = "2S") then print "tie"
There's a little less typing if you set up a temporary variable:
variable temp = comPlay concatenate humPlay
if temp = "0P" then print "Your paper covers my rock"
And so on. I think you can fill in everything else. Then your program is done! You can try it in Tom's Kitchen computer using this button. If it gets stuck or misbehaves in some way, and if you don't see how to fix it, click the red Stop sign, then the "Go Back" button to come back here.
If you cannot easily see why your program isn't working, or if you'd like to see my version anyway, then turn the page, and compare it to mine.
When your program works OK, or if you want to take a break and work on
something different, just save your program text in a separate file (copy
the text and paste it into NotePad or whatever you have for saving text on
your computer), and start learning Java.
Five Basic Concepts Sequence Iteration Conditional Variables Input/Output
<<Previous | ToC | Next >>
[2021 June 3]