2014-10-18 60 views
0

我有一个pascal问题。我在学校学习它,因为我已经使用Java,所以我有点困惑。但这不完全是为什么它不起作用。我试图做一个简单的if(条件)写(这个)else写(该)程序,运行在cmd中。 当我尝试编译下面的代码时,它说,我必须编写一个;而不是else,但这看起来很奇怪。帕斯卡尔如果其他人不工作

program Project1; 
var max : integer; 
var max2 : integer; 

begin 
    writeln('Max: Oh no, I'm an integer'); 
    writeln('Which integer is max supposed to be?'); 
    readln (max); 
    writeln('Max: I don't want to be a', max); 
    writeln('Multiply Max'); 
    readln (max2); 

    if (max = max * max2) then 
     writeln('NO, I do not want to be a', max); 
    else 
     writeln('I think I could live with being a ', max * max2); 

    readln; 
end. 
+0

双重撇号,双倍行为作为转义:Writeln('我不想成为',最大); – 2014-10-20 16:37:30

回答

2
program Project1; 
var max : integer; 
var max2 : integer; 
begin 
writeln('Max: Oh no, Im an integer'); 
writeln('Which integer is max supposed to be?'); 
readln (max); 
writeln('Max: I dont want to be a', max); 
writeln('Multiply Max'); 
readln (max2); 
if (max = max * max2) then 
writeln('NO, I do not want to be a', max) 
else 
    writeln('I think I could live with being a ', max * max2); 

readln; 
end. 

问题是与if语句,因为如果仅仅是一条线,你不需要与“接近”;“并且是字符串行的问题,不要在字符串中使用“'”

+0

问题在于字符串行,因为'你很早就关闭它,并且如果陈述如果是一行你不会需要使用; before else – Arnoldas 2014-10-18 11:20:13

+0

非常感谢:D – DysphoricUnicorn 2014-10-18 11:26:33

+0

您应该[编辑]解释您提供的修复,而不是简单地发布代码更改。如果你没有解释为什么代码需要改变,你不会在这里提供任何知识。 – 2014-10-19 07:06:07

2

尝试在writelns修理你的撇号,并看看是否有帮助:

Write apostrophe sign in writeln function - Pascal

+0

我真的没有看到,我在写作中使用和撇号。其中的内容是结束显示文本。 (我希望它打印最大值) – DysphoricUnicorn 2014-10-18 11:15:40

+0

writeln('最大:哦不,我是一个整数'); (最大:我不想成为',最大); – 2014-10-18 11:16:07

+0

你可以看到,为什么我在我编辑的答复中做到了这一点...(忘记写在那里) – DysphoricUnicorn 2014-10-18 11:17:57