Two Functions Calling The Same Array

Post Reply
the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Two Functions Calling The Same Array

Post by the_wesley_watkins »

Can someone tell me how to get this code to work? I am passing in an array and then trying to pass the array into another function that is called within the same function.

Code: Select all

DIM numbers(5)

numbers(0) = 1 ! numbers(1) = 2
numbers(2) = 3 ! numbers(3) = 4
numbers(4) = 5


DEF average(total, nums())
	avg = sumArray(nums(),total)
	avg = divide(sum, total)
	RETURN avg
END DEF


DEF sumArray(numbers(), elements)
	sum = 0
	FOR COUNT = 0 TO elements - 1
		sum+= numbers(COUNT)
	NEXT COUNT
	RETURN sum
END DEF


DEF divide(num, divisor)
	RETURN num / divisor
END DEF


PRINT average(5, numbers)

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Two Functions Calling The Same Array

Post by Mr. Kibernetik »

Code: Select all

DIM numbers(5)

numbers(0) = 1 ! numbers(1) = 2
numbers(2) = 3 ! numbers(3) = 4
numbers(4) = 5


DEF average(total, nums())
   sum = sumArray(nums,total)
   avg = divide(sum, total)
   RETURN avg
END DEF


DEF sumArray(numbers(), elements)
   sum = 0
   FOR COUNT = 0 TO elements - 1
      sum+= numbers(COUNT)
   NEXT COUNT
   RETURN sum
END DEF


DEF divide(num, divisor)
   RETURN num / divisor
END DEF


PRINT average(5, numbers)

Post Reply