2015-02-24 52 views
1
Procedure Exchangerates; 
var 
    selection: integer; 
    answer, GBP, USD, EUR, JPY: string; 
begin 
    Assignfile(ERfile, 'ER.dat'); 
    reset(ERfile); 
    while not eof(erfile) do 
    begin 
    read(erfile, er); 
    writeln('Which currency do you want to convert from, euros, pounds, dollars or yen'); 
    readln(answer); 
    if answer = 'GBP' then 
    begin 
     writeln('GBP'); 
     writeln('How many pounds to you want to convert to dollars?'); 
     readln(selection); 
     writeln(selection*er.usdtopound:0:2); 
     writeln('How many pounds do you want to convert to euros?'); 
     readln(selection); 
     writeln(selection*er.eurotopound:0:2); 
     writeln('How many pounds do you want to convert to yen?'); 
     readln(selection); 
     writeln(selection*er.yentopound:0:2) ; 
    end; 
    else 
    if answer = 'EUR' then 
     writeln('hi'); 
    end; 
    closefile(erfile); 
end; 

那是需要在货币之间进行转换的程序表单程序,当我尝试运行if语句时出现错误,出于何种原因以及如何解决它?错误是[Error] Currencyconvertor3.dpr(75):';'前 'ELSE' 不允许的,并且当我删除分号我得到3个更多的错误Delphi 7 else if语句错误?

[错误] Currencyconvertor3.dpr(75): 'END' 预期,但 'ELSE' 发现

[错误] Currencyconvertor3 .dpr(88):声明预期,但识别符 'closefile' 发现

[错误] Currencyconvertor3.dpr(90): ''预期但'''发现

+0

*我得到一个错误*是不是一个有用的问题说明。你知道究竟** **你得到了什么错误,并没有什么理由让你不包括对我们来说也是如此。 – 2015-02-24 17:50:34

+0

遗憾将编辑成我的帖子 – SidTheSloth 2015-02-24 17:51:35

+0

你得到的错误消息是问题的一个明确的指示和如何解决针锋相对。删除冒犯的分号';'解决了错误。您提到的其他错误不会在您提供的代码中出现。 – 2015-02-24 19:39:17

回答

4

而不是

end; 
else if answer = 'EUR' then 

你需要

end 
else if answer = 'EUR' then 

杂散分号结束的if声明。

如果你已经格式化你的代码更加整齐它可能已经比较明显的是你做了错事。

+0

谢谢unfortunatley我不能给予好评你,但我很感激:) – SidTheSloth 2015-02-24 17:55:36

+0

您可以接受的答案,如果你想:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-答案工作 – 2015-02-24 17:59:16