Ok, i just started using pascal, since I went to a college open evening, and they told me in the first year of the course I wish to study, i would be learning pascal. This is not a homework assignment of any kind, this is just me messing around with pascal, trying to gain some knowledge.

In writing, my problem is this. I need to take the smallest of two variables that have previously been inputted from the biggest of the two, however, either of the variables could be the biggest, or the smallest.

I've been told to use something called min/max function, which I understand I need to use begin and end again, something i've not done yet. So far, I think i've got it, but I get exitcode 201 when i run and it gets to that point.

I have done this, yet it doesn't work.

The variables are gain,gain2,max,min and resul. All are correctly declared as the correct data types.

if gain < gain2 then 
 begin
  Min:=gain;
  Max:=gain2;
 end;

else
if gain2 < gain then
 begin
  Min:=gain2;
  Max:=gain;
 end;

resul:= Max - Min;

writeln('Your answer is ')
write( resul )

Now, i'm sure this is the correct idea, correct me if i'm wrong. If this is right, do I have something in the wrong place? If its wrong, i'd be greatful for some help, but not an outright answer, i won't learn anything from copying what someone else writes.

Thanks in advance, I hope someone can help me.

Recommended Answers

All 3 Replies

Your problems are that first, you put a ";" at the end of the first "if, then" and then you had an "else", and second, you forgot to put ";"s at the end of the "write();" statements. You have to leave out the ";" that is usually at the end of an "if, then" statement if you have an "else" following it up.

Ive done those, and i still get the same exit code (201) at the same time.I cant find the problem.

if gain <= gain2 then
begin
Max := gain2;
Min := gain;
end
else
Max := gain;
Min := gain2;
end;

Result := Max - Min;

....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.