Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement.

Similar presentations


Presentation on theme: "Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement."— Presentation transcript:

1 Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement

2 Second Repeat Program Math tutor Boom!
Write a program that will randomly generate an addition problem and let the user calculate and guess the correct answer until they get it correct. At the end it will show how many guesses it took to get the problem correct. Push: Add levels of difficulty Push: Include subtraction and multiplication problems. Push: Let the user pick how many problems they would like to have you ask. Boom! Write a program that has two graphic images moving randomly around the screen until they run into each other. Then show an explosion. Push: Be able to drive one of the images and have the other image chase it at half speed. (Will need to incorporate the commands keypressed, and readkey) Push: Be able to control both of the images.

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

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

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

6 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!!!

7 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.

8 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.

9 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 "Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement."

Similar presentations


Ads by Google