{ guess.tpas - guessing game in Turbo Pascal This is written to demonstrate this language versus the same program written in other languages. 16-Oct-2004 Brendan Gregg Created this. } Program GuessingGame (input, output, fdata); Var infile,outfile: text; answer,num,guess: integer; scorefile,name,line: string; Begin scorefile := 'highscores_tpas'; num := 0; writeln('guess.tpas - Guess a number between 1 and 100'); writeln; { Generate random number } randomize; answer := random(99) + 1; { Play game } repeat num := num + 1; write('Enter guess ',num,': '); readln(guess); if guess < answer then writeln('Higher...'); if guess > answer then writeln('Lower...'); until guess = answer; writeln('Correct! That took ',num,' guesses.'); writeln; { Save high score } write('Please enter your name: '); readln(name); assign(outfile,scorefile); append(outfile); writeln(outfile,name,' ',num); close(outfile); { Print high scores } writeln('Previous high scores,'); assign(infile,scorefile); reset(infile); while not eof(infile) do begin readln( infile, line ); writeln(line); end; close(infile); End.