Pascal if / else程序语法错误 [英] Pascal if/else program syntax error
问题描述
我创建了一个程序来确定二次方程是否给出了一个真实数字作为答案,如果是,它是什么。然而,这是我第一次使用if / else,所以我的程序不会编译过其他的,并且在搜索了半个小时之后我就没有找到为什么
代码如下:
I have created a program to determine if a quadratic equation gives a 'real' number as its answer and if so, what it is. However, this is my first time working with if/else so my program won't compile past the else and, after searching for half an hour I'm no closer to finding out why Code is as follows:
program Quadratic_Equation_Solver;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, CustApp;
var
a, b, c : real;
begin
writeln('Insert the Value for a please');
readln(a);
writeln('Insert the Value for b please');
readln(b);
writeln('Insert the Value for c please');
readln(c);
if (-4*a*c<b*b) then
writeln('These variables return an imaginary quantity that');
writeln('Cannot be computed. Please try again');
readln;
(*here it breaks*) else
Writeln('The Answer is x = ',(-b+sqrt((b*b)-(4*a*c))/(2*a)):8:2);
readln;
end.
在休息时它说它需要一个分号但是没有效果
At the break it says it needs a semi-colon but that hasn't worked
推荐答案
看起来你错过了开始
和结束语句
如果
和否则
部分。编译器需要这些来确定 if
或 else
代码路径中包含哪行代码:
It looks like you're missing a begin
and end
statement inside your if
and else
sections. The compiler needs these to determine what line of code is included in the if
or the else
codepath:
if some condition then
begin
...
end
else
begin
...
end
所以在你的情况下:
program Quadratic_Equation_Solver;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, CustApp;
var
a, b, c : real;
begin
writeln('Insert the Value for a please');
readln(a);
writeln('Insert the Value for b please');
readln(b);
writeln('Insert the Value for c please');
readln(c);
if (-4*a*c>b*b) then
begin
writeln('These variables return an imaginary quantity that');
writeln('Cannot be computed. Please try again');
end
else
begin
Writeln('The Answer is x = ',(-b+sqrt((b*b)-(4*a*c))/(2*a)):8:2);
end
readln;
end.
这篇关于Pascal if / else程序语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!