Free Pascal 问题

[复制链接]
查看11 | 回复2 | 2010-8-29 11:48:53 | 显示全部楼层 |阅读模式
自己编了一个Free Pascal程序,但运行时却提示错误,错误信息如下:
Fatal: Compilation aborted
程序如下(是一个解方程的程序):
program CET;
var
k:integer;
a,b,c,d,X1,X2:real;
begin
writeln('Welcome');
readln(k);
if k=2 then

begin

write('a=');

readln(a);

if a=0 then

begin

write('b=');

readln(b);

write('c=');

readln(c);

d:=-(c/b);

writeln('X=',d);

writeln('Thank you,Press Enter to Exit the Program');

readln;

halt;

end;

if a0 then

begin

write('b=');

readln(b);

write('c=');

readln(c);

d:=b*b-4*a*c;

if d0 then

begin

X1:=(-b+sqrt(d))/(2*a);

X2:=(-b-sqrt(d))/(2*a);

writeln('X1=',X1,',','X2=',X2);

writeln('Thank you,Press Enter to Exit the Program');

readln;

halt;

end;

if d=0 then

begin

X1:=(-b+sqrt(d))/(2*a);

writeln('X1=X2=',X1);

writeln('Thank you,Press Enter to Exit the Program');

readln;

halt;

end;

end;

end;
if k=1 then

begin

write('k=');

readln(b);

write('b=');

readln(c);

d:=-(c/b);

writeln('X=',d);

writeln('Thank you,Press Enter to Exit the Program');

readln;

halt;

end;
if k1 and k2 then

begin

writeln('Error');

writeln('Thank you,Press Enter to Exit the Program');

readln;

halt;

end;
end.
再次运行,错误信息又变了,变成:
calculate equation(s) tool.pas(69,7) Error: Incompatible types: got "Boolean" expected "LongInt"
calculate equation(s) tool.pas(76,6) Fatal: There were 1 errors compiling module, stopping
calculate equation(s) tool.pas(0) Fatal: Compilation aborted

回复

使用道具 举报

千问 | 2010-8-29 11:48:53 | 显示全部楼层
if k1 and k2 then
begin
writeln('Error');
writeln('Thank you,Press Enter to Exit the Program');
readln;
halt;
end;这句的判断错了,最后的小错误不应该啊if 语句两个或以上的判断条件要打括号的if (k1)and (k2) then begin…………………………望采纳~
回复

使用道具 举报

千问 | 2010-8-29 11:48:53 | 显示全部楼层
if k=1 then
begin
write('k=');
readln(b);
write('b=');
readln(c);
d:=-(c/b);
writeln('X=',d);
writeln('Thank you,Press Enter to Exit the Pro
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行