巫师3佩罗格符文石:关于pascal的一个小题

来源:百度文库 编辑:中科新闻网 时间:2024/04/30 06:19:01
我是一个菜鸟,刚学pascal,这提不知道怎么做,请回的人发出准确的答案。
题目:编辑程序,根据输入的x值,计算y与z并输出
y=x*x+1 if x<=2.5 y=x*x-1 if x>2.5
z=-(pi/2)*x+3 if x<0 z=0 if x=0
z=(pi/2)*x-5 if x>0
谢谢!!!
我这样写他总是说不行啊
program p1;
const pi=3.14159;
var x,y,z:integer;
begin
readln(x);
if x<=2.5 then y:=x*x+1
else y:=x*x-1;
if x<0 then z:=(-x*(pi/2))+3
else begin
if x=0 then z:=0
else z:=(pi/2)*x-5;
end;
writeln(y,z);
end.
总是出现这样的字:
d.pas(8,28) Error: Incompatible types: got "S80REAL" expected "SMALLINT"
d.pas(10,18) Error: Incompatible types: got "S80REAL" expected "SMALLINT"
d.pas(12,4) Fatal: There were 2 errors compiling module, stopping

类似这样的题目,发布到网上来询问实在不应该。

自己翻教材,多思考。 题目也并没有难度。

var x,y,z:integer;
begin
readln(x);
if x<=2.5 then y=x*x+1
else y=x*x-1;
if x<0 then z=-(pi/2)*x+3
else if x=0 then z=0
else z=(pi/2)*x-5;
write(' y= ',y,' z= ',z);
end.