Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

Students also viewed these Databases questions

Question

Define capital structure.

Answered: 1 week ago

Question

List out some inventory management techniques.

Answered: 1 week ago