So i'm trying to convert this java code:
static int evenPosition(int [] num){
int sum = 0;
for(int i = 0; i < num.length; i++){
sum = (num[0] + num[2] + num[4] + num[6] + num[8] + num[10])*3;
//System.out.println(sum[i]);
}
return sum;
}
to ada code:
type numSize is range 0 .. 9999999999;
type SIZE is range 1 .. 12;
type barcode is array(SIZE) of numSize;
type odd is range 1..3;
N1 : barcode := (0, 7, 9, 4, 0, 0, 8, 0, 4, 5, 0, 1);
N2 : barcode := (0, 2, 4, 0, 0, 0, 1, 6, 2, 8, 6, 0);
N3 : barcode := (0, 1, 1, 1, 1, 0, 8, 5, 6, 8, 0, 7);
N4 : barcode := (0, 5, 1, 0, 0, 0, 1, 3, 8, 1, 0, 1);
procedure evenPosition(num : in numSize) is
sum : numSize := 0;
begin
sum := num;
for i in odd loop
sum := sum + sum;
Put_Line("This is the sum");
Put_Line(sum);
end loop;
end;
I'm very new to ADA and my question is there a way to pick specific elements like how java has
sum = (num[0] + num[2] + num[4]...)
I'm sorry if I'm not wording this right, I have tried to find different ways to do this online but can't seem to find the answer I'm looking for. Please be kind ;-;
EDIT
I'm sorry for the confusion but I manage to solve what I wanted to do.
procedure Hw2Bnguyen is
type numSize is range 0 .. 9999999999;
type SIZE is array(1 .. 12) of Integer;
--type barcode is array(SIZE) of numSize;
-- type odd is range 1..3;
-- N1 : barcode := (0, 7, 9, 4, 0, 0, 8, 0, 4, 5, 0, 1); valid
--N2 : barcode := (0, 2, 4, 0, 0, 0, 1, 6, 2, 8, 6, 0); not
-- N3 : barcode := (0, 1, 1, 1, 1, 0, 8, 5, 6, 8, 0, 7); valid
-- N4 : barcode := (0, 5, 1, 0, 0, 0, 1, 3, 8, 1, 0, 1); not
barcode : SIZE;
num : Integer := 0;
num2 : Integer := 0;
num3 : Integer := 0;
num4 : Integer := 0;
begin
begin
Put("Enter message: (press enter each time)");
for i in 1..12 loop
barcode(i) := Integer'Value(Get_Line);
end loop;
--for k in 1..SIZE'Length loop
-- Put(barcode(k));
--end loop;
for k in 1 ..1 loop
num := barcode(k);
end loop;
for k in 3 ..3 loop
num := num + barcode(k);
end loop;
for k in 5 ..5 loop
num := num + barcode(k);
end loop;
for k in 7 ..7 loop
num := num + barcode(k);
end loop;
for k in 9 ..9 loop
num := num + barcode(k);
end loop;
Put("This is an odd sum: ");Put(num*3);
New_Line;
for k in 2 ..2 loop
num2 := barcode(k);
end loop;
for k in 4 ..4 loop
num2 := num2 + barcode(k);
end loop;
for k in 6 ..6 loop
num2 := num2 + barcode(k);
end loop;
for k in 8 ..8 loop
num2 := num2 + barcode(k);
end loop;
for k in 10 ..10 loop
num2 := num2 + barcode(k);
end loop;
Put("This is an even sum: ");Put(num2);
New_Line;
num3 := (num*3) + num2;
Put("Total from both numbers: "); Put(num3);