Presentation is loading. Please wait.

Presentation is loading. Please wait.

How can you model playing rock-paper-scissors?

Similar presentations


Presentation on theme: "How can you model playing rock-paper-scissors?"— Presentation transcript:

1 How can you model playing rock-paper-scissors?
Computer Science How can you model playing rock-paper-scissors?

2 Fix the following program just The Factorials; variables
number, answer:integer; Start-O-Matic writeln('Please enter a positive integer.'); readln(nummy); factorial := 0; repeat factorial := nummy * nummy; nummy := nummy -1; until nummy := answer; writeln(' The factorial = nummy); the-bitter-end. Fix10-17Factorial

3 How do you model playing Rock-paper-scissors?
What options do you have? How can you model each of these options?

4 Case statement When When you have 3 or more choices Semantics

5 Expression must be ordinal (integer or char)
Case Syntax case expression of : WriteLn('Int is 5'); 7..12,15 : WriteLn('Between or 15'); else begin WriteLn('Undefined.'); writeln(‘Try again later’); end; {Of this choice} end;{Of the case.} Constants: if the expression resulted in a char, you would need to have character constants (Like ‘A’, ‘B’, …) Note case has no begin, but does have an end!!!

6 program CaseExample; var Choice:integer; begin writeln(‘Choose one of the following’); writeln(‘ 1 - Titan Burger’); writeln(‘ 2 - SwordFish Sandwich’); writeln(‘ 3 - Chicken Nuggets’); readln(choice); case choice of 1:begin writeln(‘Titan Burger $3.00’); writeln(‘Yum Yum’); end; 2: writeln(‘Swordfish $5.00’); 3: begin writeln(‘No Chicken’); writeln(‘We’’re very sorry’); end; {Of the case statement} end.

7 Dry run the following program casecheck; var counter:integer; begin
for counter:= 1 to 9 do case counter MOD 5 of 0:write('often '); 1:write('What '); 2,4:write('is '); 3:write('not '); end; {Of the case} end; {Of the for loop} writeln; end.

8 Program options Planet weight Quadrant check
Write a program that lets the user find their weight on any of the following planets/stars. Sun(27.94) Moon (0.17) Saturn (1.15) Mercury (0.37) Venus(0.88) Jupiter (2.64) Rock-paper-scissors against the computer (This one is tricky!) Quadrant check Input: The measure of an angle in degrees. Output: Which quadrant the angle falls into. 0<First Quadrant<90 90<Second <180 180<Third<270 270<Fourth<360 The series of quadrants starts all over again at 360. How do you handle when the angle matches an axis?


Download ppt "How can you model playing rock-paper-scissors?"

Similar presentations


Ads by Google