我遇到了帕斯卡的问题。我在学校学习,因为我已经使用Java,我有点困惑。但这并不是它无法正常工作的原因。我试图在cmd中运行一个简单的if(条件)写(this)else write(that)程序。
当我尝试编译以下代码时,它说,我必须写一个;
而不是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 :(得分:3)
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语句,因为如果只是一行,你就不需要与";"串线问题,不要使用" ' "在字符串中间
答案 1 :(得分:2)
尝试在writelns中修复撇号,看看是否有帮助: