Pascal Code for Voting Slip

时间:2018-03-20 14:26:39

标签: pascal

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 个答案:

答案 0 :(得分:1)

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

在IF-THEN之后不应该有DO。

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

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

接近结尾时,您有两个ELSE子句。应该做什么?

答案 1 :(得分:0)

以下是有关评论的更新代码:

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~1pas  致命:语法错误,;预期但发现了

该代码应该允许在数组中输入区域和区域ID的值。然后接受选民姓名,如果输入结束然后代码关闭并使用计数器变量显示选民数,否则它允许为该选民姓名输入地区ID。在此之后完成代码区ID数组以确保其正确的分区ID;如果是,则打印选民姓名和相应的区域,如果没有通知区域ID无效。

答案 2 :(得分:0)

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.

这是一个最终工作代码,具有我原本打算使用的功能。 我想出了剩下的问题并添加了一些增强功能。非常感谢所有帮助我的人。