9
9
9milesz2014-12-23 22:39:25
Pascal
9milesz, 2014-12-23 22:39:25

How to solve this problem in Turbo Pascal?

Given Z,X and Y. Calculate R=max(x+y,z,y+z) if x>y. Otherwise R=x+y+z.
Here's what I already have:

var
z,x,y,r:real;
function max(x, y, z:real):real;
begin
writeln('Vvedite X');
readln(x);
writeln('Vvedite Y');
readln(y);
writeln('Vvedite Z');
readln(z);
if (x>y)
then
R:=max(max(x+y,z),y+z);
else
R:=x+y+z;
writeln('R=',R);
end.

Actually it does not work, I do not know how to organize it correctly. It is possible that I went the wrong way at all. My friend asked me to do the task. It is clear that he would have to figure it out himself, but what can you do, a friend is a friend. I myself have not seen Pascal since the 9th grade, and it is quite possible that things "obvious" for you will turn out to be completely different for me. Therefore, I ask, as far as possible, to suggest as "clearly" as possible, if I may put it that way.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
9
9milesz, 2014-12-24
@9milesz

Here is the complete answer. Everything seems to be correct)

var
z,x,y,r:real;
function max(x,y : real) : real;
begin
   if (x > y) then max := x
   else max := y;
end;
begin
writeln('Vvedite X');
readln(x);
writeln('Vvedite Y');
readln(y);
writeln('Vvedite Z');
readln(z);
if (x>y)
then
R:=max(max(x+y,z),y+z) else R:=x+y+z;
writeln('R=',R);
end.

K
kstyle, 2014-12-23
@kstyle

write another max() function first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question