2
program ZZX1;

{$mode objfpc}{$H+}

uses
  crt,
  wincrt,
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this  };
type
  Masquerader = record
    Name, CountyCode: string;
    Payment: real;
   end;
var
  Applicant: array[1..10] of Masquerader;
  DemList: array[1..10] of string;
  BerList: array[1..10] of string;
  EsqList: array[1..10] of string;
  x:integer;
  Y:integer;
  DemCounter:integer;
  BerCounter:integer;
  EsqCounter:integer;
  DemAmount:real;
  BerAmount:real;
  EsqAmount:real;

 procedure LoadData;
 begin
    clrscr;
X:=0;
DemCounter:=0;
BerCounter:=0;
EsqCounter:=0;
DemAmount:=0;
BerAmount:=0;
EsqAmount:=0;
repeat
X:= x+1;
repeat
write('Enter Your County Code DemM or BerM or EsqM: ');
readln(Applicant[x].CountyCode);
until (Applicant[x].CountyCode= 'DemM') or (Applicant[x].CountyCode= 'BerM') or (Applicant[x].CountyCode= 'EsqM');
If Applicant[x].CountyCode = 'DemM' then
  begin
    write('Enter Your Name: ');
    readln(Applicant[x].Name);
    write('Enter Your Total Payment: ');
    readln(Applicant[x].Payment);
    clrscr;
    DemCounter:= DemCounter + 1;
    DemAmount:= DemAmount + Applicant[x].Payment;
    DemList[DemCounter]:= Applicant[x].Name;
  end;
If Applicant[x].CountyCode = 'BerM' then
  begin
    write('Enter Your Name: ');
    readln(Applicant[x].Name);
    write('Enter Your Total Payment: ');
    readln(Applicant[x].Payment);
    clrscr;
    BerCounter:= BerCounter + 1;
    BerAmount:= BerAmount + Applicant[x].Payment;
    BerList[BerCounter]:= Applicant[x].Name;
  end;
If Applicant[x].CountyCode = 'EsqM' then
  begin
    write('Enter Your Name: ');
    readln(Applicant[x].Name);
    write('Enter Your Total Payment: ');
    readln(Applicant[x].Payment);
    clrscr;
    EsqCounter:= EsqCounter + 1;
    EsqAmount:= EsqAmount + Applicant[x].Payment;
    EsqList[EsqCounter]:= Applicant[x].Name;
  end;
until x=6 ;

 end;

Procedure PrintData;
  begin
    Y:= 0;
    for y := 1 to 6 do
    begin
      writeln('Name: ', Applicant[y].Name);
      writeln('CountyCode: ', Applicant[y].CountyCode);
      writeln('Payment: ', Applicant[y].Payment:0:2);
      writeln;
    end;
    For Y:= 1 to DemCounter do
      begin
        writeln(DemList[Y]);
        writeln(DemCounter,'',' persons are registered in Demerara');
        writeln;
        writeln('DemTotal:$ ', DemAmount:0:2);
      end;
    For Y:= 1 to BerCounter do
      begin
        writeln(BerList[Y]);
        writeln(BerCounter,'',' persons are registered in Berbice');
        writeln;
        writeln('BerTotal:$ ', BerAmount:0:2);
      end;
    For Y:= 1 to EsqCounter do
      begin
        writeln(EsqList[Y]);
        writeln(EsqCounter,'',' persons are registered in Essequibo');
        writeln;
        writeln('EsqTotal:$ ', EsqAmount:0:2);
      end;
 end;
Procedure quit;
  begin
    writeln('Press <Enter> To Quit');
    readln;
  end;

begin
  LoadData;
  PrintData;
  quit;
end.

该计划目前收集了 6 个人,并按其县代码对他们进行分组,计算每个县收集的人数和金额的总和。当我在我的预期输出下方运行程序时,它会在屏幕上显示几秒钟,然后它会消失,只留下预期输出的一部分(结束部分)。请协助。

4

1 回答 1

2

如果程序到达readln;过程中的语句时键盘缓冲区中有字符quitreadln将读取这些字符并继续前进,而不是等待进一步的输入再继续。

要检查这一点,请尝试添加一个字符变量作为参数readln并将字符的 ASCII 值写入输出(或在调试器中检查其值),以查看该变量中是否有任何readln.

(编辑)

经过进一步思考,我想知道代码是否像:

For Y:= 1 to EsqCounter do
  begin
    writeln(EsqList[Y]);
    writeln(EsqCounter,'',' persons are registered in Essequibo');
    writeln;
    writeln('EsqTotal:$ ', EsqAmount:0:2);
  end;

...实际上应该是这样的:

For Y:= 1 to EsqCounter do
  begin
    writeln(EsqList[Y]);
  end;
writeln(EsqCounter,'',' persons are registered in Essequibo');
writeln;
writeln('EsqTotal:$ ', EsqAmount:0:2);

EsqCounter...因为否则和的相同值EsqTotal将是输出EsqCounter时间,这似乎没有必要。

于 2013-03-22T00:41:30.890 回答