Question: Using ADA language. We are supposed to make the Sum_From_1_To_N procedure into a function, which I did, but then I need to store the value

Using ADA language. We are supposed to make the Sum_From_1_To_N procedure into a function, which I did, but then I need to store the value returned by the function in a variable. What am I doing wrong? It keeps saying: Unmatched actual "sum" in call where sum => result.

WITH Ada.Text_Io, Ada.Integer_Text_Io;

PROCEDURE Summation (Stop_Value : Out Integer; -- Where to stop printing the table Result : Out Integer; -- Parameter to return the sum Sum : Out integer; N : OUT Integer) IS

------------------------------------ -- This program uses a procedure to -- make a table of the sums of all the -- integers from 1 to N for various -- values of N.

Function Sum_From_1_To_N (N :Integer) Return integer is Sum : Integer;

-- A procedure to sum the values from -- 1 to N and return the sum to the -- calling program.

BEGIN

Sum := 0;

-- Find the sum from 1 to N using a for loop. Summation_Loop: FOR I IN 1 .. N LOOP Sum := Sum + I; END LOOP Summation_Loop;

Return Sum;

END Sum_From_1_To_N;

BEGIN

-- Prompt user for ending value of table.

Ada.Text_IO.Put ("Please enter the size of the table: "); Ada.Integer_Text_IO.Get (Stop_Value);

-- Print table heading Ada.Text_IO.Put_Line (" Sum of Integers"); Ada.Text_IO.Put_Line (" N from 1 to N"); Ada.Text_IO.Put_Line ("-------------------------");

-- Iterate from 1 to Stop_Value, calculating the sum from 1 to -- the value of the LCV. Print_One_Row: FOR I IN 1 .. Stop_Value LOOP

-- Print the value of I. Ada.Integer_Text_IO.Put ( Item => I, Width => 6); Sum:= Sum_From_1_To_N(N => N); Result := Sum_From_1_To_N(N => N); --Calculate the sum from 1 to I. Sum_From_1_To_N ( N => I, Sum => Result);

-- Print the sum calculated in the previous step. Ada.Integer_Text_IO.Put ( Item => Result, Width => 18);

Ada.Text_IO.New_Line;

END LOOP Print_One_Row;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!