代码之家  ›  专栏  ›  技术社区  ›  Takeem Lowe

投票单Pascal代码

  •  0
  • Takeem Lowe  · 技术社区  · 6 年前
    PROGRAM VOTING_SLIP (INPUT,OUTPUT);
    
    CONST
    
    Array_size = 20;
    
    VAR
    Counter, Increment, i, j : Integer;
    Found, full_name, District_ID : string;
    DistrictArea : Array[1..20] of string;
    DistrictID : Array[1..20] of string;
    
    BEGIN
    
    WRITELN('Please Populate District Area Array');
    FOR i := 1 to 20 DO
    READLN(DistrictArea[i]);
    
    WRITELN('Input Values for District ID');
    FOR j := 1 to 20 DO
    READLN(DistrictID[i]);
    
    WRITELN('Please Enter Voter Name');
    READLN(full_name);
    
    IF (full_name <> 'END') THEN DO
    READLN(District_ID);
    Increment := 1;
    Counter := 0;
    Found := 'FALSE';
    
    WHILE(Found = 'FALSE') AND (Increment <= Array_size) DO
     IF (DistrictID[Increment] = District_ID) THEN
     Found := 'TRUE';
    ELSE
     Increment := Increment + 1;
    
    IF (Found = 'TRUE') THEN
     WRITELN (full_name,'you have been registered to vote in', 
     DistrictArea[Increment]);
     Counter := Counter + 1;
    ELSE
     Writeln ('Error! Invalid District ID');
    ELSE
     Writeln ('you have', Counter, 'registered voters. Goodbye!');
    END.
    

    上述代码不会执行第10行的pas。编译器说:

    1. 26 / 3 oneste~1.pas
     Error: Illegal expression
    2. 26 / 3 oneste~1.pas
     Error: Illegal expression
    3. 26 / 3 oneste~1.pas
     Fatal: Syntax error, ; expected but identifier READLN found
    

    有人能帮忙吗?非常感谢。

    3 回复  |  直到 6 年前
        1
  •  1
  •   Arndt Jonasson    6 年前

    你为什么说第10行?错误消息显示第26行。

    IF-THEN之后不应该有DO。

    您应该将一些语句包含在BEGIN-END块中。

    关键字ELSE和END之前有多余的分号。

    接近尾声时,您有两个其他子句。那该怎么办?

        2
  •  0
  •   Takeem Lowe    6 年前

    以下是有关注释的更新代码:

    PROGRAM VOTING_SLIP (INPUT,OUTPUT);
    
    uses crt;
    
    CONST
     Array_size = 20;
    
    VAR
     Counter, Increment, i, j : Integer;
     Found, full_name, District_ID : string;
     DistrictArea : Array[1..20] of string;
     DistrictID : Array[1..20] of string;
    
    BEGIN
    
    WRITELN('Please Populate District Area Array');
    FOR i := 1 to 20 DO
     READLN(DistrictArea[i]);
    
     WRITELN('Input Values for District ID');
     FOR j := 1 to 20 DO
     READLN(DistrictID[j]);
    
     WRITELN('Please Enter Voter Name');
    
     READLN(full_name);
    
     IF (full_name <> 'END') THEN BEGIN
     READLN(District_ID);
     Increment := 1;
     Counter := 0;
     Found := 'FALSE';
     END
    
      WHILE (Found = 'FALSE') AND (Increment <= Array_size) DO BEGIN
       IF (DistrictID[Increment] = District_ID) THEN BEGIN
       Found := 'TRUE';
       END
       ELSE BEGIN
       Increment := Increment + 1;
       END
      END
    
      IF (Found = 'TRUE') THEN BEGIN
        WRITELN (full_name,'you have been registered to vote in', 
        DistrictArea[Increment]);
        Counter := Counter + 1;
      END
      ELSE BEGIN
       Writeln ('Error! Invalid District ID');
      END
     ELSE BEGIN
      Writeln ('you have', Counter, 'registered voters. Goodbye!');
     END
    END.
    

    新编译器错误: 35/3 oneste ~ 1。pas公司 致命:语法错误;应为,但找到时为

    该代码应该允许在数组中输入地区区域和地区ID的值。然后接受投票者名称,如果输入了end,则使用计数器变量编码关闭并显示投票者数量,否则允许为该投票者名称输入地区ID。完成后,对district ID数组进行编码,以确保其具有正确的district ID;如果是,则将选民姓名和相应的地区打印到屏幕上,如果否,则通知地区ID无效。

        3
  •  0
  •   Takeem Lowe    6 年前
    PROGRAM VOTING_SLIP (INPUT,OUTPUT);
    
    uses crt;
    
    CONST
     Array_size = 20;
    
    VAR
     Counter, Increment, i, j, k : Integer;
     Found, full_name, District_ID : string;
     DistrictArea : Array[1..20] of string;
     DistrictID : Array[1..20] of string;
    
    BEGIN
    
     WRITELN('Please Populate District Area Array');
     FOR i := 1 to 20 DO BEGIN
       READLN(DistrictArea[i]);
     END;
    
     WRITELN('Input Values for District ID');
     FOR j := 1 to 20 DO BEGIN
      READLN(DistrictID[j]);
     END;
    
     For k := 1 TO 10 DO BEGIN
    
      WRITELN('Please Enter Voter Name');
    
      READLN(full_name);
    
      IF (full_name <> 'END') THEN BEGIN
       WRITELN ('Please enter District ID');
       READLN(District_ID);
       Increment := 1;
       Counter := 0;
       Found := 'FALSE';
      END;
    
       WHILE (Found = 'FALSE') AND (Increment <= Array_size) DO BEGIN
        IF (DistrictID[Increment] = District_ID) THEN BEGIN
         Found := 'TRUE';
        END
        ELSE BEGIN
        Increment := Increment + 1;
        END
       END;
    
        IF (Found = 'TRUE') THEN BEGIN
         WRITELN (full_name,' - you have been registered to vote in - ', 
         DistrictArea[Increment]);
         Counter := Counter + 1;
         END
        ELSE BEGIN
         Writeln ('Error! Invalid District ID');
        END;
    
       IF (full_name = 'END') THEN BEGIN
        Writeln ('you have - ', Counter, '- registered voters. Goodbye!');
       END
      END;
    END.
    

    这是具有我最初想要的功能的最终工作代码。 我解决了其余的问题,并添加了一些增强功能。非常感谢所有帮助过我的人。