Foretells a number
Delphi & Pascal (česká wiki)
Category: Homework in Pascal
Program: Hadaj.pas
File exe: Hadaj.exe
Program: Hadaj.pas
File exe: Hadaj.exe
Foretells a number. You can answer Yes/No only. It can guess the number you are thinking of. An interval is firmly defined. The program asks questions like "Is the number larger than ...?" or "Is the number smaller than ...?" on which you can answer Yes/No only.
{ HADAJ.PAS Copyright (c) TrSek alias Zdeno Sekerak } { Vytvorte program ktory bude hladat vami vymyslene cislo z vopred } { urceneho intervalu. Program vam kladie otazky typu "ci je cislo } { vacsie ako.." alebo "ci je cislo mensie ako ..", na ktore vy } { odpovedate len ano alebo nie. } { } { Datum:23.05.2004 http://www.trsek.com } program hadaj_cislo; uses crt; const MAX_C=100; MIN_C=-100; var min,max:integer; stred:integer; kl:char; begin WriteLn('Budem hadat ake si myslis cislo.'); WriteLn('Odpovedaj a-ano, n-nie'); WriteLn('Mysli si cislo od ',MIN_C, ' do ', MAX_C ); min:=MIN_C; max:=MAX_C; repeat stred := trunc((min + max)/2); WriteLn('Je cislo vacsie ako cislo ',stred ); kl := readkey; if((kl='a') or (kl='A'))then min:=stred+1 else max:=stred; until (min=max); WriteLn('Hladane cislo je:', min ); ReadLn; end.