unit Question3_UXXXX;

{A PROPOSED MEMORANDUM}

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ComCtrls;


type

  TfrmQuestion3 = class(TForm)
    redOutput: TRichEdit;
    BitBtn1: TBitBtn;
    bmbPlay: TBitBtn;
    procedure bmbPlayClick(Sender: TObject);
  private
    { Private declarations }
    arrUser : Array[1..5] of String;
    iSum, iSize   : Integer;
  public
    { Public declarations }
  end;

var
  frmQuestion3: TfrmQuestion3;
  arrPoints : Array[1..20] of string =
       ('12:40','20:0','13:0','3:0','15:0','9:0', '19:50','10:0',
        '8:90','11:0','1:0', '5:30','16:0','14:100','4:0','17:0',
        '18:20','6:0','7:0','2:20');

implementation

{$R *.dfm}


procedure TfrmQuestion3.bmbPlayClick(Sender: TObject);
var
    a, b,c, iChoice : integer;
    bFound       : boolean;
    sDummy       : string;
begin
   iSum := 0;
   iSize := 20;
   for a := 1 to 5 do
    begin
       iChoice := StrToInt(InPutBox('Treasure Hunt', 'Enter Choice '+inttostr(a), '0'));
       if (iChoice < 1) OR (iChoice > 20) then
         begin
           arrUser[a] := IntToStr(iChoice) + ' INVALID NUMBER';
           dec(iSum, 5);
         end
        else
         begin
           bFound := False;
           b := 0;
           while NOT bFound AND (b <= iSize) do
           begin
            inc(b, 1);
            if pos(IntToStr(iChoice)+':', arrPoints[b]) = 1
             then
              begin
                bFound := true;
                sDummy :=  arrPoints[b];
                arrUser[a] := sDummy;
                delete(sDummy, 1, pos(':',sDummy));
                inc(iSum, StrToInt(sDummy));

                for c := b to iSize-1 do
                    arrPoints[c] := arrPoints[c+1];

                dec(iSize, 1);
              end;
        end;//while
       if not bFound
        then
         begin //already used
            arrUser[a] := IntToStr(iChoice) + ' ALREADY SELECTED';
            dec(iSum, 5);
         end;
       end; // if
    end;//for

    //Display results
    redOutput.Lines.Clear;
    redOutput.Lines.Add('Numbers not selected');
    redOutput.Lines.Add('====================');
    for a := 1 to iSize do
     redOutput.Lines.Add(arrPoints[a]);

    redOutput.Lines.Add(' ');
    redOutput.Lines.Add('Participants'' choices');
    redOutput.Lines.Add('====================');
    for a := 1 to 5 do
     redOutput.Lines.Add(arrUser[a]);

    //Determine and display Prize
    if iSum < 0 then
        iSum := 0;
    redOutput.Lines.Add('Points: ' + intToStr(iSum));

    case iSum of
      0        : redOutput.Lines.Add('No Prize ');
      1..100   : redOutput.Lines.Add('Prize: Teddy Bear');
      101..200 : redOutput.Lines.Add('Prize: Fishing Rod');
      else
        redOutput.Lines.Add('Prize: Gym Membership');
    end;

end;

end.
