我收到一个错误:非法表达 [英] I'm getting an Error:Illegal Expression

查看:59
本文介绍了我收到一个错误:非法表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

illegal expression and Fatal: Syntax error, ; expected but : found

Pascal 代码如下:

The Pascal code is below:

Program PaidUp;

const
size=30;

var
   payment,totm1,totm2,totm3:real;
   section1,section2,section3,i,j,idnum:integer;
   IDNUMARR:array[1..999] of integer;
   PAYMENTARR:array[1..size] of real;


Procedure InitialiseVariables;
{This procedure initialises all variables used in the program}
   Begin
      idnum:=0;
      payment:=0;
      totm1:=0;
      totm2:=0;
      totm3:=0;
      section1:=0;
      section2:=0;
      section3:=0;
      i:=0;
      j:=0;
End; {Initialise Variables}

Procedure DeclareandInitialiseArrays;
{This procedure declares and initialises all arrays used in the program}
   Begin
      IDNUMARR:array[1..999] of integer;
      PAYMENTARR:array[1..size] of real;
         For i:=1 to size do
             begin
              idnum[i]:=0;
              payment[i]:=0;
         end; {ends for statment}
End; {Declare and Initialise Variables}

Procedure PutDataIntoArray;
{This procedure puts the data into the arrays}
   Begin
  while(idnum<>0 and payment<>0 and payment=1350 and payment=1620 and  payment=1800 and payment=1650 and payment=1980 and payment=2200) do
         begin
              writeln('Invalid value, please enter another value');
              readln(idnum);
              readln(payment);
         end;{ends while statement}
              set j:=j+1;
              idnum[j]:=idnum;
              payment[j]:=payment;
End; {Put Data Into Array}

 Procedure DetermineStatisticsInformation;
{This procedure determines which masqueraders belong to which group, tallys  the total persons in a section and totals the amount of money paid in each section for costumes}
   Begin
      For j:=1 to size do
         begin
              if(payment[j]=1350 and payment[j]=1650) then
                  begin
                       writeln('Masquerader with memid:idnum[j] belongs to  section1');
                       section1:= section1+1;
                       totm1:= totm1+payment[j];
                  end;{ends if statement}
              if(payment[j]=1620 and payment[j]=1980) then
                  begin
                       writeln('Masquerader with memid:idnum[j] belongs to section2');
                       section2:= section2+1;
                       totm2:=totm2+payment[j];
                  end;{ends if statement}
              if(payment[j]=1800 and payment[j]=2200)then
                  begin
                       writeln('Masquerader with memid:idnum[j] belongs to section3');
                       section3:= section3+1;
                       totm3:=totm3+payment[j];
                  end;{ends if statement}
End. {Determine Statistics Information}

Procedure PrintResults;
{This procedure outputs all information}
 Begin
  writeln('The number of masqueraders in section 1 is:', section1);
  writeln('The number of masqueraders in section 2 is:', section2);
  writeln('The number of masqueraders in section 3 is:', section3);
  writeln('Total Amount of money paid in section 1 is:', totm1);
  writeln('Total Amount of money paid in section 2 is:', totm2);
  writeln('Total Amount of money paid in section 3 is:', totm3);
End. {Print Results}

推荐答案

代码充满错误,永远无法编译.

The code is full of errors and would never compile.

  1. 您使用 idnum 和 payment 作为数组,但您已将其声明为整数!如果您需要数组,请改用 IDNUMARR 和 PAYMENTARR.
  2. 在第 9 行和第 10 行中,您声明了全局变量 IDNUMARR PAYMENTARR,但在过程 DeclareandInitialiseArrays 中又将其声明为局部变量
  3. 几乎所有的 if 语句都是无效的

  1. You use idnum and payment as array but you've declared it as integer! If you need the array, use IDNUMARR and PAYMENTARR instead.
  2. In line 9 and 10 you declare the global var IDNUMARR PAYMENTARR but you declare it again as a local var in the procedure DeclareandInitialiseArrays
  3. Almost all if-statements are invalid

if(payment[j]=1620 and payment[j]=1980) then

if(payment[j]=1620 and payment[j]=1980) then

and"运算符总是首先被评估,这会导致逻辑比较1620 and payment[j]"(这不是一个有效的语法).

The "and" operator is evaluated always first which results in the logical comparison "1620 and payment[j]" (which is not a valid syntax).

你必须像这样把每个比较都放在括号里:

You have to put every comparison into brackets like this:

if(payment[j]=1620) and (payment[j]=1980) then

4.设置 j:=j+1;你究竟期望会发生什么??我想你只是想增加 j

4. set j:=j+1; What exactly do you expect should happen?? I think you just want increase j

j:=j+1;

  1. 所有程序都必须以;结尾而不是.
  2. 最后的开始结束".缺少执行所有程序的位置.

可能还有很多其他...

And probably many others...

这篇关于我收到一个错误:非法表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆