Static Referencing of Member Values - Ada - ada

Hi
I am trying out my first program in Ada of creating a single player dice game.
But facing problem in maintaining score of the player.
Goal: Each player has 10 turns and scores 10 points if total of 2 rolls is 7
Problem: Every time total score gets reset and 10 does not get added to current score.
Total_Score is the final score to be displayed.
Please help!!! Any help appreciated!!!
Thanks :)
My code is as follows:
with Ada.Numerics.Discrete_Random,Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
procedure Game is
subtype Die is Integer range 1 .. 6;
subtype Dice is Integer range 2*Die'First .. 2*Die'Last;
package Random_Die is new Ada.Numerics.Discrete_Random (Die);
use Random_Die;
type MY_TYPE is range 1..10;
package My_Int_IO is new Ada.Text_IO.Integer_IO(MY_TYPE);
use My_Int_IO;
My_Range : MY_TYPE;
G : Generator;
Roll : Dice; -- Total Rolled
Roll_One : INTEGER; -- Roll 1
Roll_Two : INTEGER; -- Roll 2
Total_Score : INTEGER; -- Current Score
Choice : INTEGER; -- Game Choice
Total_Roll : INTEGER; -- Total Rolled Returned
Score : INTEGER; -- Static Score count
function Roll_Dice return INTEGER is
begin
-- Start the generator in a unique state in each run
Reset (G);
Total_Score := 0;
-- Roll a pair of dice
Roll_One := Random(G);
Roll_Two := Random(G);
Put(Roll_One,3);
Put(Roll_Two,3);
Roll := Roll_One + Roll_Two;
return Roll;
end Roll_Dice;
begin
Total_Score := 0;
for Index in MY_TYPE loop
Put("Roll Dice: Press 1 To Exit: Press 2 ");
New_Line;
Get(Item => Choice);
if Choice = 1 then
Total_Roll := Roll_Dice;
if Total_Roll = 7 then
Put("Current Score : ");
Put(Total_Score , 3);
Total_Score := Total_Score + 10;
New_Line;
Put("Your Score : ");
Put(Total_Score, 3);
else
New_Line;
Put("Sorry! you do not score");
end if;
elsif Choice = 2 then
Put("Score ");
Put(Total_Score, 3);
exit when Choice = 2;
else
Put("Wrong Choice! You lost one chance! Try Again");
end if;
end loop;
New_Line;
Put("Total Score for this game: ");
Put(Total_Score, 3);
end Game;

Every time total score gets reset and 10 does not get added to current score.
That's because you set Total_Score to zero in the Roll_Dice function:
Total_Score := 0;
10 does get added to Total_Score:
Total_Score := Total_Score + 10;
but on the subsequent roll, the total is reset to zero.

Related

what is program in plsql to check whether it is prime using function and procedure

declare
K number;
Lnumber;
f number;
function prime(n in number, I in number) return is flag
begin
i:=2;
flag:=1;
n:=&n;
for i in 2..n/2
loop
if mod(n,i)=0
then
flag:=0;
exit;
end if;
end loop;
if flag=1
then
dbms_output.put_line('prime');
else
dbms_output.put_line('not prime');
end if;
return flag;
end;
begin
k:=4;
L:=1;
f:= prime(n,i);
dbms_output.put_line(given number is ||flag);
end;
/
I am getting output as this I wonder what is wrong with my code:
Enter value for n: 4
old 9: n:=&n;
new 9: n:=4;
declare
*
ERROR at line 1:
ORA-06540: PL/SQL: compilation error
ORA-06553: PLS-906: Compilation is not possible
q2
SQL> DECLARE
num NUMBER;
3 c NUMBER;
4
5 PROCEDURE fact (x IN NUMBER, f OUT NUMBER)
6 IS
7 l_var NUMBER := 1;
8 BEGIN
9 FOR i IN 1 .. x
10 LOOP
11 l_var := l_var * i;
12 END LOOP;
13
14 f := l_var;
15 END;
16 BEGIN
17 num := 6;
18 fact (num, c);
19 DBMS_OUTPUT.put_line (' Factorial of ' || num || ' is ' || c);
20 END;
.
in this 2nd code the result is not getting displayed , not only for this even for other codes it is showing the line PL/SQL procedure successfully completed. but the results are not displaying what is wrong with it
A fixed version of q1 might be something like this (comments inline):
declare
-- k number; -- not used
-- l number; -- previously "lnumber;" not used anyway
f number;
function prime
( n in number ) -- "i" parameter never used
return number -- added return type
is
flag number := 1; -- added datatype, initial value and semicolon
begin
-- i := 2; -- Can't modify an IN parameter
-- flag := 1; -- not needed, can assign a value when declaring
-- n := &n; -- Can't modify an IN parameter
for i in 2 .. n / 2 loop
if mod(n, i) = 0 then
flag := 0;
exit;
end if;
end loop;
if flag = 1 then
dbms_output.put_line('prime');
else
dbms_output.put_line('not prime');
end if;
return flag;
end prime; -- added closing tag for clarity
begin
-- k := 4; -- not used
-- l := 1; -- not used
-- f := prime(n, i); -- n and i are not declared
f := prime(123);
dbms_output.put_line('prime check returns '|| f); -- added quotes, changed "flag" to "f"
end;
Also I formatted the code to make it more readable. This also helps when writing code, as it keeps the structure clearly visible and makes some errors more obvious.
q2 works for me, so you probably just need to check how whatever tool you are using displays dbms_output. In some tools there is a checkbox, others require a set server output on command.
You can also provide a function implementation of your factorial procedure:
declare
num number;
c number;
procedure fact
( num in number
, f out number )
is
begin
f := 1;
for i in 2 .. num loop
f := f * i;
end loop;
end fact;
function fact
( num number )
return number
is
f number;
begin
fact(num, f);
return f;
end fact;
begin
num := 6;
fact(num, c);
dbms_output.put_line('Factorial of ' || num || ' is ' || c);
dbms_output.put_line('Factorial of ' || num || ' is ' || fact(num));
end;

How to define "+" for a record type

I'm trying to create a package in ADA. I have three files, adb(main program), ads(package), and adb(body package). I can not see any problems with my main and package files. However, in my body package, I have trouble in writing a function that adds the values of P1 and P2 together and then returns its value.
My main program:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Price_Handling; use Price_Handling;
procedure Test_Price_Plus is
P1, P2 : Price_Type;
begin
P1.Dollar:= 19;
P1.Cents:= 50;
P2 := (Dollar => 10, Cents=> 0);
Put("P1 is ");
Put(P1);
New_Line;
Put("P2 is ");
Put(P2);
New_Line;
Put("If we add P1 and P2, then we get: ");
Put(P1 + P2);
New_Line;
end Test_Price_Plus;
My package:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
package Price_Handling is
type Price_Type is private;
procedure Get(Item: out Price_Type);
function "+"(Left, Right: in Price_Type) return Price_Type; -- Left(Dollar), Right(Cents)
private
type Price_Type is
record
Dollar, Cents: Integer;
end record;
end Price_Handling;
My Package Body:
Package Body Price_Handling is
procedure Put(Item:in Price_Type) is
begin
Put(Item.Dollar); Put(":");
Put(Item.Cents);
end Put;
function "+"(Left, Right: in Price_Type) return Price_type is
begin
-- Need to write a function that adds P1 and P2 together and return its value
end "+";
The easiest way for newcomers is probably just create a dummy result value and return it:
function "+"(Left, Right: in Price_Type) return Price_type is
Result : Price_Type;
begin
Result.Dollars := Left.Dollars + Right.Dollars;
Result.Cents := Left.Cents + Right.Cents;
-- If your cents are higher than 100, then we
-- need to increment dollars and adjust the cents
-- count
if Result.Cents > 99 then
Result.Dollars := Result.Dollars + 1;
Result.Cents := Result.Cents - 100;
end if;
return Result;
end "+";
However, this is really weak. Your Price_type is not design using types that can protect you from errors. If you want to leverage Ada's safety aspects, consider making a Cents subtype that restricts you to 0 to 99:
subtype Cents_Type is Natural range 0 .. 99;
That way, if you make a programming error and put in a value higher than 99 or negative, then the program will catch it and raise an exception. Same for dollars. Make a new type for non negative values:
subtype Dollars_Type is Natural;
Now update your record to use those types and also default initialize them:
type Price_Type is record
Dollars : Dollars_Type := 0;
Cents : Cents_Type := 0;
end record;
Then if you do that, you can update the + function to use a dummy variable to hold the cents in case you do go over 99 while adding them together.
function "+"(Left, Right: in Price_Type) return Price_type is
Result : Price_Type;
Cents_With_Overflow : Natural;
begin
Result.Dollars := Left.Dollars + Right.Dollars;
Cents_With_Overflow := Left.Cents + Right.Cents;
-- If your cents are higher than 100, then we
-- need to increment dollars and adjust the cents
-- count
if Cents_With_Overflow > 99 then
Result.Dollars := Result.Dollars + 1;
Result.Cents := Cents_With_Overflow - 100;
else
Result.Cents := Cents_With_Overflow;
end if;
return Result;
end "+";
Another approach for this problem is to convert the dollars and cents for each instance of Price_Type to a total number of cents. Simply add the two cents values then convert the result back to dollars and cents.
package Price_Handling is
type Price_Type is private;
function "+" (Left, Right : Price_Type) return Price_Type;
procedure Get(Item : out Price_type);
procedure Print(Item : in Price_Type);
private
subtype Cents_Type is Integer range 0..99;
type Price_Type is record
Dollars : Natural := 0;
Cents : Cents_Type := 0;
end record;
end Price_Handling;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
package body Price_Handling is
---------
-- "+" --
---------
function "+" (Left, Right : Price_Type) return Price_Type is
function To_Cents ( Item : Price_type) return Natural is
Temp : Natural := 100 * Item.Dollars + Item.Cents ;
begin
return Temp;
end To_Cents;
function To_Price(Item : in Natural) return Price_Type is
Dollars : Natural;
Cents : Cents_Type;
begin
Dollars := Item / 100;
Cents := Item mod 100;
return (Dollars, Cents);
end To_Price;
begin
return To_Price(To_Cents(Left) + To_Cents(Right));
end "+";
---------
-- Get --
---------
procedure Get (Item : out Price_type) is
begin
Put("Enter the dollars for the price: ");
Get(Item.Dollars);
Put("Enter the cents for the price: ");
Get(Item.Cents);
end Get;
-----------
-- Print --
-----------
procedure Print (Item : in Price_Type) is
begin
Put(Item => Item.Dollars, Width => 1);
Put (".");
if Item.Cents < 10 then
Put ("0");
end if;
Put (Item => Item.Cents, Width => 1);
end Print;
end Price_Handling;
with Price_Handling; use Price_Handling;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
P1 , P2 : Price_Type;
begin
Get(P1);
Get(P2);
Put("The sum of P1 and P2 is: ");
Print(P1 + P2);
New_Line;
end Main;
An example of executing this program produces the following output:
Enter the dollars for the price: 10
Enter the cents for the price: 41
Enter the dollars for the price: 0
Enter the cents for the price: 32
The sum of P1 and P2 is: 10.73
Another example showing proper incrementation of the dollars amount when the two cents amounts sum to more than a dollar is:
Enter the dollars for the price: 10
Enter the cents for the price: 52
Enter the dollars for the price: 3
Enter the cents for the price: 95
The sum of P1 and P2 is: 14.47

Formal parameter "Item" is not referenced

By using subprograms, I try to write a program that displays a VAT table. It asks the user to enter some data and based on these data, displays a VAT-table. However, I get a warning which says: "Formal parameter "Item" is not referenced". My program does display a table but it looks terrible. Here you can see how far I have come:
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,2,0);
Put(Price_Wm * (1.0 + V_percent/100.0), 15,2,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;
Here is an update: I just rewrote my code based in the comments and it works fine. Now I wonder how I can add more functions and subprograms to this code so that the Underprogram procedure looks cleaner?. Right now I have just two subprograms:
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, 2,2,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, 5,2,0);
Put((Higher + Float(I) * Step) * VAT/100.0, 13,2,0);
Put(Price_without_VAT * (1.0 + VAT/100.0), 15,2,0);
New_Line;
end loop;
end Underprogram;
The following code is your code after re-organized by the pretty printer provided in the GNAT Studio 2020 Community Edition:
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, 2, 0);
Put (Price_Wm * (1.0 + V_percent / 100.0), 15, 2, 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;
I simply copied the source into the GNAT Studio IDE, saved the file, then chose the Pretty Print option under the Code tab in the IDE. I did nothing to manually format the code.
See how the use of indentation helps visually identify the beginning and ending of procedures, functions, and loops.
The reason that the first pass through the table reports the VAT data as zero is that you pass V_Percent to Get_Pop as the actual for the out parameter Item, but you never assign to Item, with the result that the compiler assigns something to it on exit from the procedure, overwriting the value of V_Percent which you already assigned explicitly.
Get_Pop can’t logically have a single out parameter, because its job (as you’ve coded it) is to read four values. Either no parameters at all, or give each required value its own out parameter, or create a record type to hold all 4 values.

Is it necessary to wrap shared array data in a protected type?

I am aware that it is generally bad practice (and the ARM probably says that this is undefined behavior), but I am attempting to write a fast text parser containing many floating point numbers and it would be very expensive to wrap the loaded text into a protected type given that the data is examined character by character and may have up to a million floats or pass a slice on the stack.
Is it possible in Ada (GNAT) to "safely" divide up an unprotected array for consumption with multiple tasks given that the array is never written and only read?
As in:
Text : array (1..1_000_000) of Character := ...
begin
Task_1.Initialize (Start_Index => 1, End_Index => 10_000);
Task_2.Initialize (Start_Index => 10_001, End_Index => 20_000);
...
Yes. That is safe because there is no race condition associated with reading the data and there is no temporally overlapping write operation.
For example, the following code uses such a technique to perform parallel addition on an array of integers.
package Parallel_Addition is
type Data_Array is array(Integer range <>) of Integer;
type Data_Access is access all Data_Array;
function Sum(Item : in not null Data_Access) return Integer;
end Parallel_Addition;
package body Parallel_Addition is
---------
-- Sum --
---------
function Sum (Item : in not null Data_Access) return Integer is
task type Adder is
entry Set (Min : Integer; Max : Integer);
entry Report (Value : out Integer);
end Adder;
task body Adder is
Total : Integer := 0;
First : Integer;
Last : Integer;
begin
accept Set (Min : Integer; Max : Integer) do
First := Min;
Last := Max;
end Set;
for I in First .. Last loop
Total := Total + Item (I);
end loop;
accept Report (Value : out Integer) do
Value := Total;
end Report;
end Adder;
A1 : Adder;
A2 : Adder;
R1 : Integer;
R2 : Integer;
Mid : constant Integer := (Item'Length / 2) + Item'First;
begin
A1.Set (Min => Item'First, Max => Mid);
A2.Set (Min => Mid + 1, Max => Item'Last);
A1.Report (R1);
A2.Report (R2);
return R1 + R2;
end Sum;
end Parallel_Addition;
with Parallel_Addition; use Parallel_Addition;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
procedure Parallel_Addition_Test is
The_Data : Data_Access := new Data_Array (1 .. Integer'Last / 5);
Start : Time;
Stop : Time;
The_Sum : Integer;
begin
The_Data.all := (others => 1);
Start := Clock;
The_Sum := Sum (The_Data);
Stop := Clock;
Put_Line ("The sum is: " & Integer'Image (The_Sum));
Put_Line
("Addition elapsed time is " &
Duration'Image (Stop - Start) &
" seconds.");
Put_Line
("Time per addition operation is " &
Float'Image(Float(Stop - Start) / Float(The_Data'Length)) &
" seconds.");
end Parallel_Addition_Test;

expected type "..." defined at ....... error in Ada

I have such a Karatsuba algorithm implementation I have written in ADA.
procedure Karatsuba (Factor_1, Factor_2 : in Number; Product : out Number) is
m : Integer;
m2 : Integer;
low1 : Number := (0,1);
high1 : Number := (0,1);
low2 : Number := (0,1);
high2 : Number := (0,1);
z0 : Index;
z1 : Index;
z2 : Index;
x : Integer;
y : Integer;
hc1 : Index;
hc2 : Index;
begin
low1 := (others => 0);
high1 := (others => 0);
low2 := (others => 0);
high2 := (others => 0);
if Factor_1'Length = 1 or Factor_2'Length = 1 then
Standard(Factor_1, Factor_2,Product);
end if;
-- calculates the size of the numbers
m := Integer'Max(Factor_1'Length, Factor_2'Length);
m2 := m / 2;
-- split the digit sequences about the middle
for Factor_1_Index in Factor_1'Range loop
x := x + 1;
if x <= m2 then
low1(Factor_1_Index) := Factor_1(Factor_1_Index);
else
high1(hc1) := Factor_1(Factor_1_Index);
hc1 := hc1 + 1;
end if;
end loop;
for Factor_2_Index in Factor_2'Range loop
y := y + 1;
if y <= m2 then
low2(Factor_2_Index) := Factor_2(Factor_2_Index);
else
high2(hc2) := Factor_2(Factor_2_Index);
hc2 := hc2 + 1;
end if;
end loop;
-- 3 calls made to numbers approximately half the size
z0 := Karatsuba(low1, low2, Product);
z1 := Karatsuba((low1 + high1), (low2 + high2), Product);
z2 := Karatsuba(high1, high2, Product);
Product := (z2*10**(2*m2))+((z1-z2-z0)*10**(m2))+(z0);
end Karatsuba;
On the last 4 lines before "end Karatsuba" line, I get the error "expected type 'Index' defined at ...". The errors I'm receiving are, respectively,
expected type "Index" defined at ....
found package or procedure name
there is no applicable operator "+" for type "Number" defined at ......
This is another class that I have assigned some variables:
package ITI8590.Natural_Number_Multiplication is
type Digit is range 0 .. 1;
type Index is new Positive;
type Number is array (Index range <>) of Digit;
for Digit'Size use 1;
procedure Standard(Factor_1, Factor_2 : in Number; Product : out Number);
procedure Karatsuba(Factor_1, Factor_2 : in Number; Product : out Number);
end ITI8590.Natural_Number_Multiplication;
Now why I get this error? I couldn't solve it, and I'm stuck in it. Could you help me?
Thanks,
Karatsuba is a procedure, so at the end instead of
z0 := Karatsuba(low1, low2, Product);
z1 := Karatsuba((low1 + high1), (low2 + high2), Product);
z2 := Karatsuba(high1, high2, Product);
it should probably read
Karatsuba(low1, low2, z0);
Karatsuba((low1 + high1), (low2 + high2), z1);
Karatsuba(high1, high2, z2);
which requires you to declare z0, z1, z2 as Number rather than Index. Note, Product is an out parameter to the procedure, so all your code achieved was to overwrite it twice with intermediate results (3 times, counting the call to Standard above).
But then you have a problem: the compiler says
yusuf.ada:25:12: unconstrained subtype not allowed (need initialization)
yusuf.ada:25:12: provide initial value or explicit array bounds
which is calling for something related to the way you have declared low1 etc:
low1 : Number := (0,1);
high1 : Number := (0,1);
low2 : Number := (0,1);
high2 : Number := (0,1);
The trouble with this approach is that you’ve now constrained the bounds of the variables: low1 is fixed to have 2 elements (set to values that you then overwrite), and can’t be expanded. I don’t know how the algorithm is supposed to work, but this seems unlikely to be right; for a start, what happens if the inputs have more than 2 digits?
One approach that might work is to use the number of digits in the input parameters:
Max_Digits : constant Positive := Factor_1’Length + Factor_2’length;
pragma Assert (Product’Length >= Max_Digits, “possible overflow”);
low1 : Number (1 .. Max_Digits) := (others => 0);
etc.
And, as ajb has commented, you’ll need to define operators +, -, *, ** between Numbers and Integers as needed, particularly in the expression (z2*10**(2*m2))+((z1-z2-z0)*10**(m2))+(z0) in the last line of the procedure.

Resources