# Game: Guess the Number

Sorry to bother you again...

Ok, so the game was already done and, after I spent some time fixing errors and cleaning the code, I decided to add some more code...

And this time, if the user repeated the same number twice or more, a message would appear saying "You have already guessed this number".

I got this idea from an older thread:
[code]http://www.programmersheaven.com/mb/pasprog/392718/392718/need-help-with-guessing-game/?S=B20000#392718[/code]

Although the program runs with no problems after I added the code, It actually doesn't return a message after the user repeated the same number twice.

Here's the complete code for the game:
(Yeah, I know it's a lot of it and may sound stupid...)

[code]Program guess_the_number ;
uses windows ;
var a, b, c, d, f : Integer ;
e : String ;
time : dword ;
guess_easy : Array [0..100] of Boolean ;
guess_medium : Array [0..1000] of Boolean ;
guess_hard : Array [0..10000] of Boolean ;
Function checkifexists_easy : Boolean ;
Begin
If guess_easy[a] = true
then checkifexists_easy := true
else checkifexists_easy := false ;
End ;
Function checkifexists_medium : Boolean ;
Begin
If guess_medium[a] = true
then checkifexists_medium := true
else checkifexists_medium := false ;
End ;
Function checkifexists_hard : Boolean ;
Begin
If guess_hard[a] = true
then checkifexists_hard := true
else checkifexists_hard := false ;
End ;
Function Calculo_Distancia : Integer ;
Begin
Calculo_Distancia := (a - b) ;
End ;
Procedure Dificil_T_C ;
Begin
time := 0 ;
c := 0 ;
time := gettickcount ;
b := 1 ;
b := random (10000) ;
Writeln ('Enter a number between 1 and 10000:') ;
Repeat
If checkifexists_hard = true
then Writeln ('You have already guessed that number...') ;
If Calculo_Distancia > b
then If (Calculo_Distancia <= 10000) and (Calculo_Distancia >= 5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia <= 4999) and (Calculo_Distancia >= 2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia <= 1999) and (Calculo_Distancia >= 1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia <= 1249) and (Calculo_Distancia >= 675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia <= 674) and (Calculo_Distancia >= 100)
then Writeln ('Try to lower your guessing...') ;
If (Calculo_Distancia <= 99) and (Calculo_Distancia >= 50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia <= 49) and (Calculo_Distancia >= 10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia <= 9) and (Calculo_Distancia >= 2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia < b
then If (Calculo_Distancia >= -10000) and (Calculo_Distancia <= -5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia >= -4999) and (Calculo_Distancia <= -2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia >= -1999) and (Calculo_Distancia <= -1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia >= -1249) and (Calculo_Distancia <= -675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia >= -674) and (Calculo_Distancia <= -100)
then Writeln ('Try to raise your guessing...') ;
If (Calculo_Distancia >= -99) and (Calculo_Distancia <= -50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia >= -49) and (Calculo_Distancia <= -10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia >= -9) and (Calculo_Distancia <= -2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia = 1
then Writeln ('YOU ARE AT THE DISTANCE OF ONE NUMBER!!!!') ;
c := c + 1 ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries and ',time,' seconds to guess it.') ;
End ;
Procedure Dificil_Tentativas ;
Begin
c := 0 ;
b := 1 ;
b := random (10000) ;
Writeln ('Enter a number between 1 and 10000:') ;
Repeat
If checkifexists_hard = true
then Writeln ('You have already guessed that number...') ;
If Calculo_Distancia > b
then If (Calculo_Distancia <= 10000) and (Calculo_Distancia >= 5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia <= 4999) and (Calculo_Distancia >= 2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia <= 1999) and (Calculo_Distancia >= 1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia <= 1249) and (Calculo_Distancia >= 675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia <= 674) and (Calculo_Distancia >= 100)
then Writeln ('Try to lower your guessing...') ;
If (Calculo_Distancia <= 99) and (Calculo_Distancia >= 50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia <= 49) and (Calculo_Distancia >= 10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia <= 9) and (Calculo_Distancia >= 2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia < b
then If (Calculo_Distancia >= -10000) and (Calculo_Distancia <= -5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia >= -4999) and (Calculo_Distancia <= -2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia >= -1999) and (Calculo_Distancia <= -1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia >= -1249) and (Calculo_Distancia <= -675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia >= -674) and (Calculo_Distancia <= -100)
then Writeln ('Try to raise your guessing...') ;
If (Calculo_Distancia >= -99) and (Calculo_Distancia <= -50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia >= -49) and (Calculo_Distancia <= -10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia >= -9) and (Calculo_Distancia <= -2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia = 1
then Writeln ('YOU ARE AT THE DISTANCE OF ONE NUMBER!!!!') ;
c := c + 1 ;
Until a = b ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries to guess it.') ;
End ;
Procedure Dificil_Cronometro ;
Begin
time := 0 ;
time := gettickcount ;
c := 0 ;
b := 1 ;
b := random (10000) ;
Writeln ('Enter a number between 1 and 10000:') ;
Repeat
If checkifexists_hard = true
then Writeln ('You have already guessed that number...') ;
If Calculo_Distancia > b
then If (Calculo_Distancia <= 10000) and (Calculo_Distancia >= 5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia <= 4999) and (Calculo_Distancia >= 2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia <= 1999) and (Calculo_Distancia >= 1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia <= 1249) and (Calculo_Distancia >= 675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia <= 674) and (Calculo_Distancia >= 100)
then Writeln ('Try to lower your guessing...') ;
If (Calculo_Distancia <= 99) and (Calculo_Distancia >= 50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia <= 49) and (Calculo_Distancia >= 10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia <= 9) and (Calculo_Distancia >= 2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia < b
then If (Calculo_Distancia >= -10000) and (Calculo_Distancia <= -5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia >= -4999) and (Calculo_Distancia <= -2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia >= -1999) and (Calculo_Distancia <= -1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia >= -1249) and (Calculo_Distancia <= -675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia >= -674) and (Calculo_Distancia <= -100)
then Writeln ('Try to raise your guessing...') ;
If (Calculo_Distancia >= -99) and (Calculo_Distancia <= -50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia >= -49) and (Calculo_Distancia <= -10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia >= -9) and (Calculo_Distancia <= -2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia = 1
then Writeln ('YOU ARE AT THE DISTANCE OF ONE NUMBER!!!!') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',time,' seconds to guess it.') ;
End ;
Procedure Medio_T_C ;
Begin
time := 0 ;
c := 0 ;
time := gettickcount ;
b := 1 ;
b := random (1000) ;
Writeln ('Enter a number between 1 and 1000:') ;
Repeat
c := c + 1 ;
If checkifexists_medium = true
then Writeln ('You have already guessed that number...') ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries and ',time,' seconds to guess it.') ;
End ;
Procedure Medio_Tentativas ;
Begin
c := 0 ;
b := 1 ;
b := random (1000) ;
Writeln ('Enter a number between 1 and 1000:') ;
Repeat
c := c + 1 ;
If checkifexists_medium = true
then Writeln ('You have already guessed that number...') ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
Until a = b ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries to guess it.') ;
End ;
Procedure Medio_Cronometro ;
Begin
time := 0 ;
time := gettickcount ;
b := 1 ;
b := random (1000) ;
Writeln ('Enter a number between 1 and 1000:') ;
Repeat
If checkifexists_medium = true
then Writeln ('You have already guessed that number...') ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',time,' seconds to guess it.') ;
End ;
Procedure Facil_T_C ;
Begin
time := 0 ;
c := 0 ;
time := gettickcount ;
b := 1 ;
b := random (100) ;
Writeln ('Enter a number between 1 and 100:') ;
Repeat
c := c + 1 ;
If checkifexists_easy = true
then Writeln ('You have already guessed that number...') ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries and ',time,' seconds to guess it.') ;
End ;
Procedure Facil_Tentativas ;
Begin
c := 0 ;
b := 1 ;
b := random (100) ;
Writeln ('Enter a number between 1 and 100:') ;
Repeat
c := c + 1 ;
If checkifexists_easy = true
then Writeln ('You have already guessed that number...') ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
Until a = b ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries to guess it.') ;
End ;
Procedure Facil_Cronometro ;
Begin
time := 0 ;
time := gettickcount ;
b := 1 ;
b := random (100) ;
Writeln ('Enter a number between 1 and 100:') ;
Repeat
If checkifexists_easy = true
then Writeln ('You have already guessed that number...') ;
If a < b
then Writeln ('Too small..') ;
If a > b
then Writeln ('Too big...') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',time,' seconds to guess it.') ;
End ;
Procedure Modo_Jogo ;
Begin
Writeln ('Choose the game mode:') ;
Writeln ('') ;
Writeln ('By tries: 1') ;
Writeln ('By time: 2') ;
Writeln ('Both: 3') ;
Writeln ('') ;
If (d = 1) and (f = 1)
then Facil_Tentativas ;
If (d = 1) and (f = 2)
then Facil_Cronometro ;
If (d = 1) and (f = 3)
then Facil_T_C ;
If (d = 2) and (f = 1)
then Medio_Tentativas ;
If (d = 2) and (f = 2)
then Medio_Cronometro ;
If (d = 2) and (f = 3)
then Medio_T_C ;
If (d = 3) and (f = 1)
then Dificil_Tentativas ;
If (d = 3) and (f = 2)
then Dificil_Cronometro ;
If (d = 3) and (f = 3)
then Dificil_T_C ;
End ;
Begin
Writeln ('Choose the difficulty:') ;
Writeln ('') ;
Writeln ('Easy: 1') ;
Writeln ('Medium: 2') ;
Writeln ('Hard: 3') ;
Writeln ('') ;
Modo_Jogo ;
End ;
Procedure Game_Over ;
Begin
Writeln ('Game Over') ;
End ;
Procedure Retry ;
Begin
Writeln ('') ;
Writeln ('Try again? Y/N') ;
If e = ('Y')
else Game_Over ;
End ;
Begin
Repeat
Retry ;
Until e = ('N') ;
End.[/code]

• [code][blue]program guess_the_number;
uses windows;
var a,b,tries:byte;
time:dword;
c:array[0..100] of boolean; { triggers }

begin
fillchar(c,sizeof(c),0); { <-- Init "c" with "false" values (0) }
randomize;
tries:=0;
a:=succ(random(100));
time:=gettickcount; { <-- Get time from system counter, it gets updated every ms }
repeat
write(#13#10'Enter a number between 1 and 100 (0 to Exit) : ');readln(b);
if ((b in[0..100]) and not(c[[b]b[/b]])) then begin { <-- Perform range check for "b" also check trigger }
c[[b]b[/b]]:=true; { <-- Set trigger }
inc(tries);
if b=0 then begin writeln(#13#10'Exiting...');halt;end;
if a<b then writeln('Too big...') else
if a>b then writeln('Too small...');
end else if (b in[1..100]) then writeln('Number already entered !')
else writeln('Must be in 0..100 range !'); { <-- Out of range warning }
until a=b;
time:=trunc((gettickcount-time)/1000); { <-- calculate elapsed time }
writeln(#13#10#13#10'You took ',time,' seconds and ',tries,' tries to guess it.');readln;
end.[/code]

• Does that only work on numbers within the range of 1 and 100?

I mean... whenether I try to enlarge the range (Between 1 and 1000 or 1 and 10000), it gives me an error saying "Warning: Range check error while evaluating constants" and it treats as if the numbers were ranging between 1 and 100 while in reality they were ranging between 1 and 1000 or 1 and 10000.
• : Does that only work on numbers within the range of 1 and 100?
:
: I mean... whenether I try to enlarge the range (Between 1 and 1000
: or 1 and 10000), it gives me an error saying "Warning: Range check
: error while evaluating constants" and it treats as if the numbers
: were ranging between 1 and 100 while in reality they were ranging
: between 1 and 1000 or 1 and 10000.

The [b]in[/b] relational operator works with [b]set[/b]s only, I should have mention it... For bigger ranges it has to be exchanged with something like this: [b] if ((b>0) and (b<=[red]your upper range here[/red])) ...[/b]

• The range limit message works, but a message still doesn't appear when I repeat the same number twice.

Here's an example of how I put it on a range of 1 and 1000:

[code]Procedure Medio_T_C ;
Begin
fillchar(guess_medium,sizeof(guess_medium),0) ;
time := 0 ;
c := 0 ;
time := gettickcount ;
b := 1 ;
b := random (1000) ;
Writeln ('Enter a number between 1 and 1000:') ;
Repeat
c := c + 1 ;
[color=Red][b] If ((a > 0) and (b <= 1000)) then Begin
guess_medium[a] := true ;[/b][/color]
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
[color=Red][b] End else If ((a > 0) and (b <= 1000))[/b][/color]
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 1000!') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries and ',time,' seconds to guess it.') ;
End ;[/code]
• [code][color=Blue]program guess_the_number;
uses windows;
const max_range=[red][b]1000[/b][/red]; { <-- change this to any maximum range }
var a,b,tries:word;
time:dword;
c:array[0..max_range] of boolean; { triggers }

begin
fillchar(c,sizeof(c),0); { <-- Init "c" with "false" values (0) }
randomize;
tries:=0;
a:=succ(random(max_range));
time:=gettickcount; { <-- Get time from system counter, it gets updated every ms }
repeat
write(#13#10'Enter a number between 1 and ',max_range,' (0 to Exit) : ');readln(b);
if (((b>=0) and (b<=max_range)) and not(c[[b]b[/b]])) then begin { <-- Perform range check for "b" also check trigger }
c[[b]b[/b]]:=true; { <-- Set trigger }
inc(tries);
if b=0 then begin writeln(#13#10'Exiting...');halt;end;
if a<b then writeln('Too big...') else
if a>b then writeln('Too small...');
end else if ((b>=0) and (b<=max_range)) then writeln('Number already entered !')
else writeln('Must be in 0..100 range !'); { <-- Out of range warning }
until a=b;
time:=trunc((gettickcount-time)/1000); { <-- calculate elapsed time }
writeln(#13#10#13#10'You took ',time,' seconds and ',tries,' tries to guess it.');readln;
end.
[/color][/code]
• It's finished!
I spent 2 weeks on it and it occupies a total of 401 lines.

If you're interested, here's the source code for it:

[code]Program guess_the_number ;
uses windows ;
var a, b, c, d, f : Byte ;
e : String ;
time : dword ;
guess_easy : Array [0..100] of Boolean ;
guess_medium : Array [0..1000] of Boolean ;
guess_hard : Array [0..10000] of Boolean ;
Function Calculo_Distancia : Integer ;
Begin
Calculo_Distancia := (a - b) ;
End ;
Procedure Dificil_T_C ;
const max_range = 10000 ;
Begin
fillchar(guess_hard,sizeof(guess_hard),0) ;
time := 0 ;
c := 0 ;
time := gettickcount ;
b := 1 ;
b := random (10000) ;
Writeln ('Enter a number between 1 and 10000:') ;
Repeat
If ((a > 0) and (b <= max_range)) and not (guess_hard[a]) then Begin
guess_hard[a] := true ;
If Calculo_Distancia > b
then If (Calculo_Distancia <= 10000) and (Calculo_Distancia >= 5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia <= 4999) and (Calculo_Distancia >= 2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia <= 1999) and (Calculo_Distancia >= 1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia <= 1249) and (Calculo_Distancia >= 675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia <= 674) and (Calculo_Distancia >= 100)
then Writeln ('Try to lower your guessing...') ;
If (Calculo_Distancia <= 99) and (Calculo_Distancia >= 50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia <= 49) and (Calculo_Distancia >= 10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia <= 9) and (Calculo_Distancia >= 2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia < b
then If (Calculo_Distancia >= -10000) and (Calculo_Distancia <= -5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia >= -4999) and (Calculo_Distancia <= -2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia >= -1999) and (Calculo_Distancia <= -1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia >= -1249) and (Calculo_Distancia <= -675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia >= -674) and (Calculo_Distancia <= -100)
then Writeln ('Try to raise your guessing...') ;
If (Calculo_Distancia >= -99) and (Calculo_Distancia <= -50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia >= -49) and (Calculo_Distancia <= -10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia >= -9) and (Calculo_Distancia <= -2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia = 1
then Writeln ('YOU ARE AT THE DISTANCE OF ONE NUMBER!!!!') ;
End else If ((a > 0) and (b <= max_range))
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 10000!') ;
c := c + 1 ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries and ',time,' seconds to guess it.') ;
End ;
Procedure Dificil_Tentativas ;
const max_range = 10000 ;
Begin
fillchar(guess_hard,sizeof(guess_hard),0) ;
c := 0 ;
b := 1 ;
b := random (10000) ;
Writeln ('Enter a number between 1 and 10000:') ;
Repeat
If ((a > 0) and (b <= max_range)) and not (guess_hard[a]) then Begin
guess_hard[a] := true ;
If Calculo_Distancia > b
then If (Calculo_Distancia <= 10000) and (Calculo_Distancia >= 5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia <= 4999) and (Calculo_Distancia >= 2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia <= 1999) and (Calculo_Distancia >= 1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia <= 1249) and (Calculo_Distancia >= 675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia <= 674) and (Calculo_Distancia >= 100)
then Writeln ('Try to lower your guessing...') ;
If (Calculo_Distancia <= 99) and (Calculo_Distancia >= 50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia <= 49) and (Calculo_Distancia >= 10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia <= 9) and (Calculo_Distancia >= 2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia < b
then If (Calculo_Distancia >= -10000) and (Calculo_Distancia <= -5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia >= -4999) and (Calculo_Distancia <= -2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia >= -1999) and (Calculo_Distancia <= -1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia >= -1249) and (Calculo_Distancia <= -675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia >= -674) and (Calculo_Distancia <= -100)
then Writeln ('Try to raise your guessing...') ;
If (Calculo_Distancia >= -99) and (Calculo_Distancia <= -50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia >= -49) and (Calculo_Distancia <= -10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia >= -9) and (Calculo_Distancia <= -2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia = 1
then Writeln ('YOU ARE AT THE DISTANCE OF ONE NUMBER!!!!') ;
End else If ((a > 0) and (b <= max_range))
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 10000!') ;
c := c + 1 ;
Until a = b ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries to guess it.') ;
End ;
Procedure Dificil_Cronometro ;
const max_range = 10000 ;
Begin
fillchar(guess_hard,sizeof(guess_hard),0) ;
time := 0 ;
time := gettickcount ;
c := 0 ;
b := 1 ;
b := random (10000) ;
Writeln ('Enter a number between 1 and 10000:') ;
Repeat
If ((a > 0) and (b <= max_range)) and not (guess_hard[a]) then Begin
guess_hard[a] := true ;
If Calculo_Distancia > b
then If (Calculo_Distancia <= 10000) and (Calculo_Distancia >= 5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia <= 4999) and (Calculo_Distancia >= 2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia <= 1999) and (Calculo_Distancia >= 1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia <= 1249) and (Calculo_Distancia >= 675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia <= 674) and (Calculo_Distancia >= 100)
then Writeln ('Try to lower your guessing...') ;
If (Calculo_Distancia <= 99) and (Calculo_Distancia >= 50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia <= 49) and (Calculo_Distancia >= 10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia <= 9) and (Calculo_Distancia >= 2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia < b
then If (Calculo_Distancia >= -10000) and (Calculo_Distancia <= -5000)
then Writeln ('You''re too far away...') ;
If (Calculo_Distancia >= -4999) and (Calculo_Distancia <= -2000)
then Writeln ('You''re not too far away...') ;
If (Calculo_Distancia >= -1999) and (Calculo_Distancia <= -1250)
then Writeln ('You''re not that near...') ;
If (Calculo_Distancia >= -1249) and (Calculo_Distancia <= -675)
then Writeln ('You''re near...') ;
If (Calculo_Distancia >= -674) and (Calculo_Distancia <= -100)
then Writeln ('Try to raise your guessing...') ;
If (Calculo_Distancia >= -99) and (Calculo_Distancia <= -50)
then Writeln ('You''re very near...') ;
If (Calculo_Distancia >= -49) and (Calculo_Distancia <= -10)
then Writeln ('You''re almost there!') ;
If (Calculo_Distancia >= -9) and (Calculo_Distancia <= -2)
then Writeln ('You''re a few steps from guessing!!') ;
If Calculo_Distancia = 1
then Writeln ('YOU ARE AT THE DISTANCE OF ONE NUMBER!!!!') ;
End else If ((a > 0) and (b <= max_range))
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 10000!') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',time,' seconds to guess it.') ;
End ;
Procedure Medio_T_C ;
const max_range = 1000 ;
Begin
fillchar(guess_medium,sizeof(guess_medium),0) ;
time := 0 ;
c := 0 ;
time := gettickcount ;
b := 1 ;
b := random (1000) ;
Writeln ('Enter a number between 1 and 1000:') ;
Repeat
c := c + 1 ;
If ((a > 0) and (b <= max_range)) and not (guess_medium[a]) then Begin
guess_medium[a] := true ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
End else If ((a > 0) and (b <= max_range))
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 1000!') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries and ',time,' seconds to guess it.') ;
End ;
Procedure Medio_Tentativas ;
const max_range = 1000 ;
Begin
fillchar(guess_medium,sizeof(guess_medium),0) ;
c := 0 ;
b := 1 ;
b := random (1000) ;
Writeln ('Enter a number between 1 and 1000:') ;
Repeat
c := c + 1 ;
If ((a > 0) and (b <= max_range)) and not (guess_medium[a]) then Begin
guess_medium[a] := true ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
End else If ((a > 0) and (b <= max_range))
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 1000!') ;
Until a = b ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries to guess it.') ;
End ;
Procedure Medio_Cronometro ;
const max_range = 1000 ;
Begin
fillchar(guess_medium,sizeof(guess_medium),0) ;
time := 0 ;
time := gettickcount ;
b := 1 ;
b := random (1000) ;
Writeln ('Enter a number between 1 and 1000:') ;
Repeat
If ((a > 0) and (b <= max_range)) and not (guess_medium[a]) then Begin
guess_medium[a] := true ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
End else If ((a > 0) and (b <= max_range))
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 1000!') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',time,' seconds to guess it.') ;
End ;
Procedure Facil_T_C ;
Begin
fillchar(guess_easy,sizeof(guess_easy),0) ;
time := 0 ;
c := 0 ;
time := gettickcount ;
b := 1 ;
b := random (100) ;
Writeln ('Enter a number between 1 and 100:') ;
Repeat
c := c + 1 ;
If ((a in[1..100]) and not(guess_easy[a])) then Begin
guess_easy[a] := true ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
End else If (a in[1..100])
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 100!') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries and ',time,' seconds to guess it.') ;
End ;
Procedure Facil_Tentativas ;
Begin
fillchar(guess_easy,sizeof(guess_easy),0) ;
c := 0 ;
b := 1 ;
b := random (100) ;
Writeln ('Enter a number between 1 and 100:') ;
Repeat
c := c + 1 ;
If ((a in[1..100]) and not(guess_easy[a])) then Begin
guess_easy[a] := true ;
If a < b
then Writeln ('Too small...') ;
If a > b
then Writeln ('Too big...') ;
End else If (a in[1..100])
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 100!') ;
Until a = b ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',c,' tries to guess it.') ;
End ;
Procedure Facil_Cronometro ;
Begin
fillchar(guess_easy,sizeof(guess_easy),0) ;
time := 0 ;
time := gettickcount ;
b := 1 ;
b := random (100) ;
Writeln ('Enter a number between 1 and 100:') ;
Repeat
If ((a in[1..100]) and not(guess_easy[a])) then Begin
guess_easy[a] := true ;
If a < b
then Writeln ('Too small..') ;
If a > b
then Writeln ('Too big...') ;
End else If (a in[1..100])
then Writeln ('You have already guessed that number...')
else Writeln ('Your number must be between 1 and 100!') ;
Until a = b ;
time:=trunc((gettickcount-time) div 1000) ;
If a = b
then Writeln ('You did it! The correct number was ',b,'!') ;
Writeln ('You took ',time,' seconds to guess it.') ;
End ;
Procedure Modo_Jogo ;
Begin
Writeln ('Choose the game mode:') ;
Writeln ('') ;
Writeln ('By tries: 1') ;
Writeln ('By time: 2') ;
Writeln ('Both: 3') ;
Writeln ('') ;
If (d = 1) and (f = 1)
then Facil_Tentativas ;
If (d = 1) and (f = 2)
then Facil_Cronometro ;
If (d = 1) and (f = 3)
then Facil_T_C ;
If (d = 2) and (f = 1)
then Medio_Tentativas ;
If (d = 2) and (f = 2)
then Medio_Cronometro ;
If (d = 2) and (f = 3)
then Medio_T_C ;
If (d = 3) and (f = 1)
then Dificil_Tentativas ;
If (d = 3) and (f = 2)
then Dificil_Cronometro ;
If (d = 3) and (f = 3)
then Dificil_T_C ;
End ;
Begin
Writeln ('Choose the difficulty:') ;
Writeln ('') ;
Writeln ('Easy: 1') ;
Writeln ('Medium: 2') ;
Writeln ('Hard: 3') ;
Writeln ('') ;
Modo_Jogo ;
End ;
Procedure Game_Over ;
Begin
Writeln ('Game Over') ;
End ;
Procedure Retry ;
Begin
Writeln ('') ;
Writeln ('Try again? Y/N') ;
If e = ('Y')
else Game_Over ;
End ;
Begin