每当我打印列表时,它都会跳过第一个输出,我该如何纠正呢?

时间:2019-02-04 03:42:06

标签: freepascal

每当我尝试打印选民名单(输出)时,首先要输入名为a,b,c,d和e的5个合格人员的信息,而其他5个不合格的名为f,g,h,i, j。当它应该是a,b,c,d,e时,它将输出b,c,d,e,f作为有效选民

PROGRAM List_of_Eligible_Voters;
{States whether a person is a valid voter or not}


Const
YOE=2019;


VAR
Felony_Status: string;
Eligibility:ARRAY[1..10] of string;
Name:ARRAY[1..10] OF string;
YOB,Age:integer;
Count:integer;
i:integer;




BEGIN
i:=0;
Count:=0;

     FOR i:= 1 TO 10 DO
     Begin

          Name[i]:='Name';
          Eligibility[i]:='Eligibility';
     End;

          Writeln('Please enter the name of the person.');
          Readln (Name[Count]);
          Writeln ('Please enter the year of birth of the person.');
          Readln (YOB);
          Writeln ('Have the person ever been convicted of a felony?()Answer with yes/no.');
          Readln (Felony_Status);
          While (YOB <> 0) AND (Count<=10) Do
           begin
                Age:= YOE-YOB;
                IF (Age>= 18) AND (Felony_Status = 'no')Then

                   Eligibility[Count]:= 'yes'
                ELSE

                   Eligibility[Count]:= 'no';

                   Writeln('Please enter the name of the person.');
                   Readln (Name[Count]);
                   Writeln ('Please enter the year of birth of the person.');
                   Readln (YOB);
                   Writeln ('Have the person ever been convicted of a felony?()Answer with yes/no.');
                   Readln (Felony_Status);
                   COUNT:=COUNT+1;
          END;
                 Writeln ('List of Eligible Candidates');
                 FOR i:= 1 TO Count DO
                     begin
                     IF  Eligibility[i]= 'yes' THEN
                         Writeln (Name[i], '()is eligible to vote.');

                     END;
                         readln;
END.

1 个答案:

答案 0 :(得分:3)

看起来您在编写时使用Count作为索引(i),然后在阅读时使用Index作为索引。计数基于0,索引基于1。您是否尝试过同步两者?