2015-02-24 147 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