Answer the question
In order to leave comments, you need to log in
How to fix incorrect work with else?
Program qwert;
const n=12;
var
A : array [1..N] of integer;
i : integer;
b : integer;
begin
for i := 1 to N do
begin
A[i] := random (30) - 20;
b := ( A[i]);
if b < 0 then
begin
b := 0;
writeLn ('A[', i, '] = ', b);
else b >= 0 then
writeLn ('A[', i, '] = ', b);
end;
end.
Answer the question
In order to leave comments, you need to log in
syntactically the structure should be
if условие then
begin
....
end
else if условие2 then
begin
...
end;
else b <= 0 thenis inside the first if block. because the compiler and swears. Having only the code here that is now in question - I can assume that you are trying to write something like this (this is strange from the point of view of logic, because the second block will be executed only if b = 0, but we have what we have)
Program qwert;
const n=12;
var
A : array [1..N] of integer;
i : integer;
b : integer;
begin
for i := 1 to N do
begin
A[i] := random (30) - 20;
b := ( A[i]);
if b < 0 then
begin
b := 0;
writeLn ('A[', i, '] = ', b);
end
else if b <= 0 then
writeLn ('A[', i, '] = ', b);
end;
end.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question