Guess the number/With feedback (player): Difference between revisions

Add Seed7 example
(Add Seed7 example)
Line 1,578:
(set! minimum (+ guess 1)))))
(display "I was RIGHT!\n")</lang>
 
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
$ include "keybd.s7i";
 
const proc: main is func
local
var boolean: okay is FALSE;
var boolean: quit is FALSE;
var integer: low is 1;
var integer: high is 1000;
var integer: guess is 0;
var char: command is ' ';
begin
writeln("Choose a number between 1 and 1000.");
write("Press Enter and I will start to guess the number.");
readln;
repeat
guess := low + (high - low) div 2;
write("My guess is: " <& guess);
write(". How did I score (l=too low, h=too high, c=correct, q=quit)? ");
flush(OUT);
repeat
command := lower(getc(KEYBOARD));
until command in {'l', 'h', 'c', 'q'};
writeln(command);
case command of
when {'l'}: low := succ(guess);
when {'h'}: high := pred(guess);
when {'c'}: okay := TRUE;
when {'q'}: quit := TRUE;
end case;
until quit or okay or low > high;
if not quit then
writeln("So the number is: " <& guess);
if low > high then
writeln("Why did you cheat?");
end if;
end if;
writeln("It was nice to play with you.");
end func;</lang>
 
Example
<pre>
Choose a number between 1 and 1000.
Press Enter and I will start to guess the number.
My guess is: 500. How did I score (l=too low, h=too high, c=correct, q=quit)? h
My guess is: 250. How did I score (l=too low, h=too high, c=correct, q=quit)? l
My guess is: 375. How did I score (l=too low, h=too high, c=correct, q=quit)? h
My guess is: 312. How did I score (l=too low, h=too high, c=correct, q=quit)? l
My guess is: 343. How did I score (l=too low, h=too high, c=correct, q=quit)? l
My guess is: 359. How did I score (l=too low, h=too high, c=correct, q=quit)? l
My guess is: 367. How did I score (l=too low, h=too high, c=correct, q=quit)? h
My guess is: 363. How did I score (l=too low, h=too high, c=correct, q=quit)? l
My guess is: 365. How did I score (l=too low, h=too high, c=correct, q=quit)? c
So the number is: 365
It was nice to play with you.
</pre>
 
=={{header|Smalltalk}}==