Programs to Complete: Answerer

Peter Hearnshaw's Answerer is an entertaining, deceptively simple program. The aim is to make the program output acceptable answers to as many questions from the user as possible. In order to run it and develop it, you need to download starters.txt and include it in the program folder. We show the console with a typical output before the program code.

Example Q and A session

Q&A

program Answerer;
  {$APPTYPE CONSOLE}
{
    Copyright (c) 2010 Peter Hearnshaw

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}
uses
  SysUtils;
var
  Tinput, Tfile, TOutput : string;
  f: Text;
begin
  writeln('Please only ask me questions, i answer any question');
  repeat
    TOutput := '';
    write('YOU: ');
    readln(Tinput);
    Tinput := lowercase(Tinput);
    Assign(f,'starters.txt');
    Reset(f); {'Reset(x)' - means open the file x}
    Repeat
      Readln(f,TFile);
      if(pos(TFile, Tinput)>0)then
        begin
          Readln(f,TFile);
          TOutput := 'ME: ' + TFile;
        end;
    Until Eof(f);
    Close(f);
    if(TOutput='')then
      begin
        TOutput := 'ME: What?!?';
      end;
    writeln(TOutput);
  until 'this program' = 'failure';
end.

Programming - a skill for life!

Unfinished programs for you to complete