help: source code for calculator

i have made a new version of the fraction calculator. can anyone see why this source code doesn't work?

thanks

[code]
program fractions2(input,output);
var m,n,i,j : integer;
k,l : char;
procedure gcd(y,g : integer; var gcd : integer);
begin
while (y>0) and (g>0) do
if y>=g then y := y mod g else g :=j mod g;
gcd:=y+g
end;
function fraction(o,p : integer;) : integer;
begin
read(o);readln;
read(p);readln;
if (o>p) then
writeln(o div p, ’ ’, (o mod p)/gcd(o,p));
writeln(’=’, ’ ’, ’−−−−’);
writeln(’ ’, p/gcd(o,p))
end;
procedure addf(u,v,d,f,z,c : integer);
begin
z:=v*f;
c:=(u*f)+(v*d);
writeln(’ ’, u, ’ ’, d,’ ’, c);
Writeln(’Sum is: ’, ’ −−− ’, ’+’, ’ −−− ’, ’=’, ’−−−−−−−−−−−’, fraction
(c,z));
writeln(’ ’, v, ’ ’, f, ’ ’, z)
end;
procedure multiply(u,v,d,f,z,c : integer);
begin
z:=v*f;
c:=u*d;
writeln(u, ’*’, d, ’ ’, c);
writeln(’−−−−−’, ’ = ’, ’−−−−’, ’=’, fraction(c,z));
writeln(v, ’*’, f, ’ ’, z)
end;
procedure subtract(u,v,d,f,z,c : integer);
begin
z:=v*f;
c:=(u*f)−(v*d);
writeln(’ ’, u, ’ ’, v,’ ’, c);
Writeln(’Sum is: ’, ’ −−− ’, ’−’, ’ −−− ’, ’=’, ’ −−−−−−−−−−−’, fractio
n(c,z));
writeln(’ ’, v, ’ ’, f, ’ ’, ’ ’, z)
end;
procedure divide(u,v,d,f,z,c : integer);
begin
if d=0 then writeln(’data not acceptable’)
else
z:=v*d;
c:=u*f;
writeln(u, ’*’, f, ’ ’, c);
writeln(’−−−−−−’, ’ = ’, ’ −−−−’, ’=’, fraction(c,z));
writeln(v, ’*’, d, ’ ’, z);
end;

begin

writeln(’Do you want to perform operations with fractions (y/n)’);
read(l);readln;
while (l=y) do
begin
writeln(’Give data’);
writeln(’Give first fraction’);
writeln(’Give numerator:’);
read(m);readln;
writeln(’Give denominator’);
read(n);readln;
writeln(’Give second fraction’);
writeln(’Give numerator’);
read(i);readln;
writeln(’Give denominator’);
read(j);readln;
if (n=0) or (j=0) or (i<0) or (j<0) or (m<0) or (n<0) then
begin
writeln(’data not acceptable−cannot proceed’)
end.
else
case k of
’*’ : multiply(m,n,i,j);
’/’ : divide(m,n,i,j);
’+’ : addf(m,n,i,j);
’−’ : subtract(m,n,i,j)
end;
end;
end.

[/code]
Sign In or Register to comment.

Howdy, Stranger!

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

Categories