I'm practicing recursive problems for upcoming exams and have gotten stuck on this problem.
The program is supposed to take N amount of floats and multiply them together, all using recursion.
Example: The user inputs 2, then the program will take 2 floats from the user, say for example 2.0 and 3.0. Then the result is 6.0.
My attempted solution is the code below. The core problem that I have is that I don't know how I'm supposed to multiply the floats together in a way that works. Right now all my program does is that it takes N amount of floats and then just prints the last one without multiplying them all together. I do feel like the solution is simple but I really cannot find it. Would love some help on this one, thanks in advance.
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 Recprac3 is
----------------------------------
procedure Calc(N : in Integer;
F : out Float) is
Prod : Float;
begin
if N = 0 then
Put("The product is: ");
Put(Prod, 2, 2, 0); -- 2, 2, 0 is formatting
else
Get(F);
F := Prod; -- <------- Problem area
Prod := Prod * F;
Calc((N-1), F);
end if;
end Calc;
----------------------------------
N : Integer;
F : Float;
begin
Put("Get an integer: ");
Get(N);
Put("Get ");
Put(N, Width => 0);
Put(" floats: ");
Calc(N, F);
end Recprac3;