如何解决语法错误,期望有“;”但找到了“IF”?

huangapple go评论53阅读模式
英文:

How do I resolve syntax error, ";" expected but "IF" found?

问题

以下是您的代码,我将提取并翻译您要求的部分:

以下是我的代码,但是,我似乎无法使我的第二个if语句运行。我该如何解决这个问题?

Program HelloUser(input, output);
var
  UserName: string;
  Hobby: string;
  Age: integer;
Begin {main}
  Writeln('Hello user, please input your name.');
  Readln(UserName);
  Writeln('Nice to meet you, ', UserName, '. 让我们更好地相互了解。你最喜欢的爱好是什么?');
  Readln(Hobby);
  Writeln('不错哦!', Hobby, '也是我的最爱!', UserName, ',你今年多大了?');
  Readln(Age);
If Age > 16 then
Begin {If}
  Writeln(Age, '是我的幸运数字,真是巧合!我想我们将来能相处得很好,', UserName, '。');
End {If}
Else
Begin {Else}
  Writeln('哇,你还太年轻了,不应该在互联网上冒险,等年纪再大点吧。现在,多出去锻炼锻炼身体吧!');
End {Else}
If Age = 16 then
Begin {If}
  Writeln('哇!真巧,', Age, '是我的幸运数字,也是我的创建者的年龄!我期待未来能再次与你互动!');
End {If}
End.{Main}

希望这有助于您理解和解决代码中的问题。如果您需要进一步的帮助,请随时提问。

英文:

The following is my code displayed below, however, I seem to be having trouble getting my second if statement running. How do I resolve this?

Program HelloUser(input,output);
var
  UserName:string;
  Hobby:string;
  Age:integer;
Begin{main}
  Writeln('Hello user, please input your name.');
  Readln(UserName);
  Writeln('Nice to meeet you, ',UserName,'. Lets get to know each other better. What is your favorite hobby?');
  Readln(Hobby);
  Writeln('Nice one! ',Hobby,' is my favorite hobby too! How old are you, ',UserName,'?');
  Readln(Age);
If Age > 16 then
Begin {If}
  Writeln(Age,' is my favorite number, what a coincidence! I think we''ll be able to get along well in the future, ',UserName,'.');
End {If}
Else
Begin {Else}
  Writeln('Wow, you''re quite young to be trekking the Internet, why not enter this domain when you''re a bit older. In the meantime, exercise those bones of yours outside!');
End {Else}
If Age = 16 then
Begin {If}
  Writeln('Wow! What a coincidence,',Age,' is my favorite number and',Age,' is the age of my creator! I think we''ll be  able to get along well in the future, I look forward to interacting with you again!');
End {If}
End.{Main}

Depending on the user's input, 3 different outcomes should occur based on the age variable.

答案1

得分: 1

错误消息中明确表示,编译器期望出现 ;,但找到了 if

Begin {Else}
    Writeln('哇,你还太年轻,上网冒险,为什么不在年纪大一点再进入这个领域呢?与此同时,外面锻炼一下你的骨头吧!');
  End; {Else} // 在这里添加 ;
If Age = 16 then

如果需要进一步的翻译,请告诉我。

英文:

As is it is clear in the error message, the compiler is expecting ; but if is found.

Begin {Else}
    Writeln('Wow, you''re quite young to be trekking the Internet, why not enter this domain when you''re a bit older. In the meantime, exercise those bones of yours outside!');
  End; {Else} // Add ; here
If Age = 16 then

huangapple
  • 本文由 发表于 2023年5月11日 07:39:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223239.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定