任何人都可以更正这个Pascal代码

任何人都可以更正这个Pascal代码,pascal,Pascal,我需要这个代码的帮助。我不认识帕斯卡。但我必须用pascal编写一个代码。我试过了。但是有一些错误,有人能帮我吗 Program Arrayexamp(output); Var counter,index,input: Integer; A: Array[1..15] of Integer; B: Array[1..15] of Integer; begin For index := 1 to 15 do begin read(input)

我需要这个代码的帮助。我不认识帕斯卡。但我必须用pascal编写一个代码。我试过了。但是有一些错误,有人能帮我吗

    Program Arrayexamp(output); 

  Var 
  counter,index,input: Integer; 
  A: Array[1..15] of Integer;
   B: Array[1..15] of Integer;

begin
  For index := 1 to 15 do
  begin  
    read(input);
    A[index] := input;
    index++
  end

    For counter := 1 to 15 do
    begin
    if (counter mod 2 = 0) Then 
      B[counter] = A[counter] * 3 
    Else B[counter]=A[counter]-5; 
    end
end.
错误是:

pas(14,3)错误:非法表达式

source.pas(16,5)错误:非法表达式


pas(16,5)致命:语法错误,“;”预期,但“FOR”find

如果您学会正确缩进(格式化)代码,问题就非常清楚了。这个答案基于您发布的原始代码,在您添加更多代码并删除一些代码以进行更改之前。然而,答案中的信息仍然与问题相关

您发布的内容:

Program Arrayexamp(output); Var counter,index,input: Integer; A : Array[1..15] of Integer;

begin

For index := 1 to 15 do
 begin  read(input);
A[index] := input;
    index++
end; 

begin 
For index := 1 to 15 do

If (counter mod 2 = 0) Then B[counter]=A[counter]*3 Else B[counter]=A[counter]-5; end.
它的格式是否正确:

Program Arrayexamp(output); 

Var 
  counter,index,input: Integer; 
  A : Array[1..15] of Integer;

begin
  For index := 1 to 15 do 
  begin  
    read(input);
    A[index] := input;
    index++
  end; 

  begin 
    For index := 1 to 15 do
      If (counter mod 2 = 0) Then 
        B[counter] = A[counter] * 3 
      Else B[counter]=A[counter]-5; 
end.
问题很明显:您有一个
开始
,但没有匹配的
结束位于下块中。实际上,
begin
完全没有必要,可以删除

第二个问题是
for
循环本身会增加循环变量,因此在循环内修改该计数器是非法的。删除
index++行。(见下一段。)

第三个问题是Pascal不支持增量前或增量后运算符,因此
index++
是无效语法。使用
索引:=索引+1
Inc(索引)取而代之

代码编写得更为恰当:

Program Arrayexamp(output); 

Var 
  counter,index,input: Integer; 
  A: Array[1..15] of Integer;

begin
  For index := 1 to 15 do
  begin  
    read(input);
    A[index] := input;
  end; 

  For index := 1 to 15 do
    if (counter mod 2 = 0) Then 
      B[counter] = A[counter] * 3 
    Else B[counter]=A[counter] - 5; 
end.

有关Pascal中
begin..end
的语法和用法的更多信息,请参阅我为编写的回答。有些错误是无用的,除非您告诉我们这些错误到底是什么。他们在屏幕上,就在你面前。你没有理由不把它们包括在你的帖子里,所以我们也有它们。另外,如果你正确地格式化你的代码,问题就很明显了。可能是@nil的重复:不,不是。还有其他问题。读我的答案。(我写了你建议的副本的答案,并在我的帖子中链接了它。它不是副本。)