Hi, I am having some troubles understanding array. I am trying to create a function that takes an array of 20 integers and returns the average as an integer. How do I define them? When I do the codes, am I going to type each of the integer variable of the array out like this: Number, Number, Number …? Also, am I going to put ‘1’ for the dimension property? Thanks in advance. Sincerely, Sylvia Tsang Management Software Solutions, Inc. firstname.lastname@example.org
First of all, you cannot be sure that the average of 20 integers will be an integer value. Most likely it will be a Decimal. You define the number of elements in an array in the Properties of the variable. That means, if the property contains the value 20, then there are 20 elements in the array. You have to fill in each element in the array individually, by adressing the element like this: IntArr := 3; IntArr := 5; etc. However, you can use a control variable in a loop to fill in, like this: FOR i := 1 to ARRAYLEN(IntArr) DO BEGIN IntArr[i] := whatever value you want to fill in END; Please note the use of ARRAYLEN, which makes your loop independent of the number of dimensions in the array. Lars Strøm Valsted ------------------------- Software development today is a race between the programmers trying to make better and more foolproof programs, and the universe trying to make bigger idiots. So far the universe is winning.
Hi You can also pass and an array as a parameter of a function so Procedure FindAvg(IntArr) :Decimal EXIT( (IntArr+ IntArr+ IntArr+ IntArr+ …)/20); Would be a quick and dirty procedure to return the average of a twenty element array. Paul Baxter