Sid*_*oth 0 delphi if-statement
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;
Run Code Online (Sandbox Code Playgroud)
这是需要在货币之间转换的程序表单程序,当我尝试运行if语句时出现错误,任何原因以及如何修复它?错误是[错误] Currencyconvertor3.dpr(75):';' 在'ELSE'之前不允许,当我删除半冒号时我得到3个错误
[错误] Currencyconvertor3.dpr(75):'END'预期但找到'ELSE'
[错误] Currencyconvertor3.dpr(88):预期声明但找到标识符'closefile'
[错误] Currencyconvertor3.dpr(90):'.' 预期,但';' 发现
代替
end;
else if answer = 'EUR' then
Run Code Online (Sandbox Code Playgroud)
你需要
end
else if answer = 'EUR' then
Run Code Online (Sandbox Code Playgroud)
虚假的分号结束了if声明.
如果你已经更整齐地格式化了代码,那么你做错了可能会更加明显.