Download presentation
Presentation is loading. Please wait.
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
Fix this program. There is a copy on the class website.
Phicks.pas
8
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.