Presentation is loading. Please wait.

Presentation is loading. Please wait.

How can you make a guessing game?

Similar presentations


Presentation on theme: "How can you make a guessing game?"— Presentation transcript:

1 How can you make a guessing game?
Computer Science 1 How can you make a guessing game?

2 Learning Objectives Be able to read, fix and write a program that uses a repeat .. until loop.

3 Guessing game What do you need to be able to do?
How many guesses will it take the user to guess correctly? Minimum Maximum

4 Repeat..until When Semantics
When you want to repeat something an unknown number of times and at least once. Semantics Initialize variable (Pick the number the other person needs to guess) Repeat Get/calculate variable (Make a guess) Do all the other stuff you want to repeat (Have the timer ticking, tell them if the guess is too high or too low, etc.) Until variable = flag (They guessed correctly)

5 Syntax Repeat Until (condition); {All the commands to be repeated}
It will repeat until the condition is true. If the condition is false when it gets to the until line, it will repeat again.

6 Dry run sample program dryRunRepeat; var a,b,c:integer; begin b:=1;
c:= a + 2*b; writeln(a:6, b:6, c:6); a:= a + c div b; until (a>25); end.

7 program petepete; var x,y,z:integer; begin x:= 24; z:= 4; repeat if (x mod 2 = 0) then writeln('Dino ', x); x := x DIV z; end else writeln('Bam bam ', x); x:= x - z; end; until (x<1); end. Dry Run

8 Fix this program. There is a copy on the class website.
Phicks.pas

9 Program options Guessing game. Implement the guessing game, but also include showing how many guesses it took the user to guess the number. The computer picks a number (1-100) and you guess it. The computer needs to tell you if your guess is high or low. When you guess it correctly, the computer shows how many guesses it took. Push: Write a program where the computer guesses the number you enter. Make this as efficient as possible without cheating. Ulam’s conjecture: If you take any positive integer greater than one. If it is even you divide it by two, if it is odd, you multiply it by 3 and add 1. When you continue this process, you will eventually get down to 1. Write a program to verify or disprove this conjecture.

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


Download ppt "How can you make a guessing game?"

Similar presentations


Ads by Google