Need help - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Need help

Posts: 1Member
Hi I am biginner on pascal so... i can't understand where my mistake..

[code]program Bigest;
var a,b,c,d,e : integer;
begin
if a > b then
if a > c then
if a > d then
if a > e then writeln('Bigest',a)
else writeln('Bigest',e)
else if d > c then
if c > e then writeln('Bigest',b)
else writeln('Bigest',e)
else if d > e then writeln('Bigest',d)
else writeln('Bigest',e)
else if b > c then
if b > d then
if b > e then writeln('Bigest',b)
else writeln('Bigest' ,e)
else if d > e then writeln('Bigest',d)
else writeln('Bigest',e)
else if c > d then
if c > e then writeln('Bigest',c)
else writeln('Bigest',e)
else if d > e then writeln('Bigest',d)
else writeln('Bigest',e)
end.
[/code]

• Posts: 268Member
Looks like you complicated yourself with those [b]then..else[/b] statements, here's one approach (works fine with a limited number of variables):[code]var a,b,c,d,e,biggest:integer;
begin
if ((a>b) and (a>c) and (a>d) and (a>e)) then biggest:=a;
if ((b>a) and (b>c) and (b>d) and (b>e)) then biggest:=b;
if ((c>a) and (c>b) and (c>d) and (c>e)) then biggest:=c;
if ((d>a) and (d>b) and (d>c) and (d>e)) then biggest:=d;
if ((e>a) and (e>b) and (e>c) and (e>d)) then biggest:=e;
writeln('Biggest ',biggest);
end.[/code]When dealing with large quantities just use a loop to skim through the whole data and compare each value with a test value (initialized as zero), if bigger then set this test value to the last value read and at the end you'll have the biggest:[code]var biggest:integer;
t:array[1..5] of integer;
i:byte;
begin
biggest:=0;
for i:=1 to 5 do begin
write('Enter value no.',i,' :');