Being new to Ada, I'm exploring its syntax and rules and I would like to draw attention on the code given next. Here I'm trying to set a variable Actual_Stiffness to hold a constant value. Its value is given by the product:
Actual_Stiffness := Stiffness_Ratio * Stiffness_Total
where Stiffness_Total has been defined to be a constant Long_Float in the specification file Material_Data.ads and Stiffness_Total has a value already set in the ads file.
WITH Ada.Text_IO;
WITH Ada.Long_Float_Text_IO;
WITH Material_Data;
USE Material_Data;
PROCEDURE sample IS
Stiffness_Ratio : Long_Float;
Actual_Stiffness : CONSTANT Long_Float := Stiffness_Ratio * Stiffness_Total;
BEGIN -- main program
Ada.Text_IO.Put("Enter stiffness ratio: ");
Ada.Long_Float_Text_IO.Get(Item => Stiffness_Ratio);
Ada.Long_Float_Text_IO.Put(Item => Stiffness_Ratio);
--Ada.Text_IO.New_Line;
--Ada.Long_Float_Text_IO.Put(Item => Actual_Stiffness);
--Ada.Text_IO.New_Line;
--Ada.Long_Float_Text_IO.Put(Item => Stiffness_Total);
END sample;
On compiling I get the warning message
warning: "Stiffness_Ratio" may be referenced before it has a value
and on running the program, Actual_Stiffness doesn't get the right value. I could defined Actual_Stiffness to be just a Long_Float (without adding CONSTANT) and then get its value from the product Actual_Stiffness := Stiffness_Ratio * Stiffness_Total after BEGIN in my program when Stiffness_Ratio would have already gotten a value. This would be the right thing to do.
My question is:
I have defined Stiffness_Total as a constant Long_Float with a prescribed value. How to define Actual_Stiffness to be constant also (as it won't be changing in the program) while keeping the ability for a user to interactively being able to enter a Stiffness_Ratio at the terminal? Is that even possible to do?
Thanks a lot..