with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
with Ada.Numerics; use Ada.Numerics;
procedure AdaO11 is
procedure Calculate_Angles (Sa, Hc, : in Float;
Va, Vb, Vc : out Float) is
begin
Va := Arcsin(Sa / Hc);
Vb := Arccos(Sa / Hc);
Vc := 90.0;
end Calculate_Angles;
procedure Angle_Program is
Hc, Sa : Integer;
Va : Float;
begin
Put("Type in the length of the hypotenuse: ");
Get(Hc);
Put("Type in the opposite catheus: ");
Get(Sa);
New_Line;
Put("Va: ");
Put(Calculate_Angles(Va));
end Angle_Program;
Selection : Integer;
begin
Put_Line("Welcome to the calculator!")
end AdaO11;
所以,我想知道为什么我得到一个错误,当我试图计算的角度。我做错什么了吗?我真的看不出有什么错误。我调用2个参数,然后发送3个。错误可能在我的那部分代码中。
如有任何帮助,不胜感激。
我调用了2个参数,然后我发送了3个。
是的,你的子程序名为Calculate_Angles
有5个形式参数,2个模式为in
, 3个模式为out
。
错误可能在我的代码的那一部分。
不,问题是你在哪里调用Angle_Program
中的子程序:
-
Calculate_Angles
是procedure
,而不是function
,所以没有Put
使用的结果。 -
您必须在调用中提供实际变量,并且它们必须在数量和类型上与形式参数匹配。因此,
Angle_Program
需要五个变量——两个来自用户,三个用于保存Calculate_Angles
的结果。
procedure Angle_Program is
Hc, Sa : Float;
Va, Vb, Vc : Float;
begin
…
Calculate_Angles (Sa, Hc, Va, Vb, Vc);
…
end;
作为题外话,三角Elementary Functions
使用弧度。要匹配Vc
值,请指定合适的Cycle
参数来获取度数:
Va := Arcsin (Sa / Hc, 360.0);
Vb := Arccos (Sa / Hc, 360.0);
的典型输出,比较这个计算器,看起来像这样:
Type in the length of the hypotenuse: 5
Type in the opposite cathetus: 3
Va: 36.8699
Vb: 53.1301
Vc: 90.0000
我关心的是期望的标识符。
有鉴于此,
procedure Calculate_Angles (Sa, Hc, : in Float;…
^
@Jesper言论,相应的错误消息是:
ada011.adb:17:39: identifier expected
这是由第17行第39位的错误引起的——一个假的逗号。当声明子程序的参数规范时,编译器合理地期望定义标识符列表在逗号之后有另一个定义标识符。