未引用形式参数“项目”

问题描述

我尝试使用子程序编写一个显示增值税表的程序。它要求用户输入一些数据,并根据这些数据显示增值税表。但是,我收到一条警告,上面写着:“未引用形式参数“ Item””。我的程序确实显示了一个表格,但是看起来很糟糕。在这里,您可以看到我走了多远:

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;

procedure Underprogram is
V_percent,S_length,H_price,L_price,Price_Wm : Float;
 X: Integer;

procedure Get_Pop(Item : out Float ) is
begin
  Put_Line("Write ur first price:");
Get(H_price,width=>0);
while H_price < 0.0 loop
  Put("Wrong inout,try again! : ");
  Get(H_price);
end loop;

loop
Put_Line("Write in your second price:");
  Get(L_price,width=>0);
  if H_price > L_price then
  exit; end if; end loop;

Put_Line("Which VAT percent do ypu want? ");
Get(V_percent,width=>0);
while V_percent > 100.0 or V_percent <= 0.0 loop
  Put_Line("The vat percent you fed in is invalid,try again! ");
  Get(V_percent);
  end loop;

Put_Line("Which step length do you want? ");
Get(S_length,width=>0);
while S_length < 0.1 or S_length > 1.0 loop
  Put_Line("The step length you just fed in is out of the range: ");
  Get(S_length);
end loop;  end Get_Pop;

procedure Put_pop(Item : in Float) is
  
  begin
  X := Integer(Float'Floor((H_price-L_price) / S_length + 1.0));
Put_Line("              === Vattabell ===               ");
Put_Line("Price without VAT    Vat      Price with VAT ");
Put_Line("---------------     ----      -------------- ");
for I in 0..X -1  loop

 Price_Wm := L_price + Float(I) * S_length;
 Put(Price_Wm,5,2,0);

 Put((L_price + Float(I) * S_length) * V_percent/100.0,13,0);

  Put(Price_Wm * (1.0 +  V_percent/100.0),15,0);

  New_Line;
end loop;
  end Put_pop;
begin
Get_Pop(V_percent); Put_pop(V_percent);
Get_Pop(S_length);  Put_pop(S_length);
Get_Pop(H_price); Put_pop(H_price);
Get_Pop(L_price); Put_pop(L_price);
Get_Pop(Price_Wm); Put_pop(Price_Wm);
  end Underprogram;

这是一个更新:我只是根据注释重新编写了代码,并且工作正常。现在,我想知道如何在此代码中添加更多功能和子程序,以使Underprogram过程看起来更干净?现在我只有两个子程序:

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;
  
procedure Underprogram is
Higher,Lower,VAT,Step,Price_without_VAT: Float;
X                        : Integer;
procedure Get_data(Item: out Float) is
begin
  Get(Item);
end Get_data;
procedure Put_data(Item: in Float) is
begin
  Put(Item,0); Put(" ");
end Put_data;
begin
Put("Write the higher price: ");
Get_data(Higher);
while Higher < 0.0 loop
Put("Wrong input,try again: ");
Get_data(Higher); end loop;
  
loop
Put("Write the lower price: ");
     Get_data(Lower);
     if Lower < Higher then
        exit; end if; end loop;
     
  Put("Write the VAT : ");
  Get_data(VAT);
  while VAT > 100.0 or VAT < 0.0 loop
     Put("Wrong input,try again:");
     Get_data(VAT);
     end loop;
     
     loop
        Put("Write the step: ");
        Get_data(Step);
        if Step > 0.0 then
        exit; end if; end loop;
 Put_data(Higher);
 Put_data(Lower);
 Put_data(VAT);
 Put_data(Step);

 X := Integer(Float'Floor((Higher-Lower) / Step + 1.0));
Put_Line("              === VATTABELL ===               ");
Put_Line("Price without VAT      VAT      Price with VAT ");
Put_Line("---------------     ----      -------------- ");
for I in 0..X -1  loop

  Price_without_VAT := Higher + Float(I) * Step;
  Put(Price_without_VAT,0);
  Put((Higher + Float(I) * Step) * VAT/100.0,0);
  Put(Price_without_VAT * (1.0 +  VAT/100.0),0);
  New_Line;
end loop;
end Underprogram;

解决方法

以下代码是由GNAT Studio 2020社区版中提供的漂亮打印机重新组织后的代码:

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;

procedure Underprogram is
   V_percent,S_length,H_price,L_price,Price_Wm : Float;
   X                                               : Integer;

   procedure Get_Pop (Item : out Float) is
   begin
      Put_Line ("Write ur first price:");
      Get (H_price,Width => 0);
      while H_price < 0.0 loop
         Put ("Wrong inout,try again! : ");
         Get (H_price);
      end loop;

      loop
         Put_Line ("Write in your second price:");
         Get (L_price,Width => 0);
         if H_price > L_price then
            exit;
         end if;
      end loop;

      Put_Line ("Which VAT percent do ypu want? ");
      Get (V_percent,Width => 0);
      while V_percent > 100.0 or V_percent <= 0.0 loop
         Put_Line ("The vat percent you fed in is invalid,try again! ");
         Get (V_percent);
      end loop;

      Put_Line ("Which step length do you want? ");
      Get (S_length,Width => 0);
      while S_length < 0.1 or S_length > 1.0 loop
         Put_Line ("The step length you just fed in is out of the range: ");
         Get (S_length);
      end loop;
   end Get_Pop;

   procedure Put_pop (Item : in Float) is

   begin
      X := Integer (Float'Floor ((H_price - L_price) / S_length + 1.0));
      Put_Line ("              === Vattabell ===               ");
      Put_Line ("Price without VAT    Vat      Price with VAT ");
      Put_Line ("---------------     ----      -------------- ");
      for I in 0 .. X - 1 loop

         Price_Wm := L_price + Float (I) * S_length;
         Put (Price_Wm,5,2,0);

         Put ((L_price + Float (I) * S_length) * V_percent / 100.0,13,0);

         Put (Price_Wm * (1.0 + V_percent / 100.0),15,0);

         New_Line;
      end loop;
   end Put_pop;
begin
   Get_Pop (V_percent);
   Put_pop (V_percent);
   Get_Pop (S_length);
   Put_pop (S_length);
   Get_Pop (H_price);
   Put_pop (H_price);
   Get_Pop (L_price);
   Put_pop (L_price);
   Get_Pop (Price_Wm);
   Put_pop (Price_Wm);

end Underprogram;

我只是将源代码复制到GNAT Studio IDE中,保存了文件,然后在IDE中的“代码”选项卡下选择了“漂亮打印”选项。我没有手动格式化代码。 了解缩进的使用如何在视觉上识别过程,函数和循环的开始和结束。

,

第一次通过表格将增值税数据报告为零的原因是,您将public function edit(Users $user) public function destroy(Users $user) 传递给V_Percent作为Get_Pop参数out的实际值,但是 you 从未分配给Item,结果是编译器在退出过程时为其分配了 something ,从而覆盖了Item的值您已经明确分配了。

V_Percent在逻辑上不能只有一个Get_Pop参数,因为它的工作(正如您所编码的一样)是读取四个值。要么根本没有任何参数,要么为每个必需的值赋予自己的out参数,或者创建一个记录类型以容纳所有4个值。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...