Answered by:
adding, average and how many numbers in an array
Question

Answers

If you have all the numbers in an array called value[], you do number=Array.getItemCount(value)
for i=1 to number sum=sum+value[i] endfor
and average=sum/number
Jan [ WhTurner ] The Netherlands
 Proposed as answer by litdevModerator Sunday, November 1, 2015 3:39 PM
 Marked as answer by litdevModerator Friday, November 13, 2015 8:34 PM

The flow of your program should be:
1. enter or read a number of values (my last eexample.)
2. use getitemcount to know the number of values
3. calculate the sum for these values
4. calculate the average.
I hope you can do it with these examples , because I am going offline now. Tomorrow I will be back.
Jan [ WhTurner ] The Netherlands
 Marked as answer by litdevModerator Friday, November 13, 2015 8:35 PM
All replies

If you have all the numbers in an array called value[], you do number=Array.getItemCount(value)
for i=1 to number sum=sum+value[i] endfor
and average=sum/number
Jan [ WhTurner ] The Netherlands
 Proposed as answer by litdevModerator Sunday, November 1, 2015 3:39 PM
 Marked as answer by litdevModerator Friday, November 13, 2015 8:34 PM

If you have all the numbers in an array called value[], you do number=Array.getItemCount(value)
for i=1 to number sum=sum+value[i] endfor
and average=sum/number
Jan [ WhTurner ] The Netherlands
could you show me what it would look like in a sub? what all would go in there? would it be a sub name then the formula and then end the sub? and those formulas work when you don't have specific numbers to use?

If you have all the numbers in an array called value[], you do number=Array.getItemCount(value)
for i=1 to number sum=sum+value[i] endfor
and average=sum/number
Jan [ WhTurner ] The Netherlands
could you show me what it would look like in a sub? what all would go in there? would it be a sub name then the formula and then end the sub? and those formulas work when you don't have specific numbers to use?
and they all have to be a separate sub for my program so i need to know how to do that in 3 subs. 

You can put each of my lines into a sub, e.g.
sub calc_sum
for i= 1 to number
sum=sum+value[i]
endfor
endsub
and the other two are even easier.
Jan [ WhTurner ] The Netherlands
so i do that but change the formula for each one? just do it like you did and change the name and how you did it would be ok? 
You can put each of my lines into a sub, e.g.
sub calc_sum
for i= 1 to number
sum=sum+value[i]
endfor
endsub
and the other two are even easier.
Jan [ WhTurner ] The Netherlands
so i do that but change the formula for each one? just do it like you did and change the name and how you did it would be ok?

The number of items in an array is reported by Array.getItemCount(name_of_array) . So I don't see any advantage to use a subroutine
If you want to see how to use a statement : type in the SmallBasic window: Array and there pops up how to use the statement (on the right) This works for all SBstatements. Didn't you use these very helpfull explanations?
Jan [ WhTurner ] The Netherlands

The number of items in an array is reported by Array.getItemCount(name_of_array) . So I don't see any advantage to use a subroutine
If you want to see how to use a statement : type in the SmallBasic window: Array and there pops up how to use the statement (on the right) This works for all SBstatements. Didn't you use these very helpfull explanations?
Jan [ WhTurner ] The Netherlands
i get how to use them i was just wondering. and i would need a sub because it is one of my menu items or would i just put that in my menu directly? 

The number of items in an array is reported by Array.getItemCount(name_of_array) . So I don't see any advantage to use a subroutine
If you want to see how to use a statement : type in the SmallBasic window: Array and there pops up how to use the statement (on the right) This works for all SBstatements. Didn't you use these very helpfull explanations?
Jan [ WhTurner ] The Netherlands
i get how to use them i was just wondering. and i would need a sub because it is one of my menu items or would i just put that in my menu directly?

The number of items in an array is reported by Array.getItemCount(name_of_array) . So I don't see any advantage to use a subroutine
If you want to see how to use a statement : type in the SmallBasic window: Array and there pops up how to use the statement (on the right) This works for all SBstatements. Didn't you use these very helpfull explanations?
Jan [ WhTurner ] The Netherlands
i get how to use them i was just wondering. and i would need a sub because it is one of my menu items or would i just put that in my menu directly?
I dont yet have an array for get item count so what do i do? do i need to make one?

Yes, dependent how you have to enter your values (read from file or enter from keyboard).
For the latter case:
val=1 'any value not equal zero
while val<>0
val = Textwindow.Read()
i=i+1
value[i]=val
endwhile
value[i] = "" ' to remove the last value 0
Then you can enter many numbers, and when you enter a 0 the program continues after the endwhile.
Jan [ WhTurner ] The Netherlands

Yes, dependent how you have to enter your values (read from file or enter from keyboard).
For the latter case:
val=1 'any value not equal zero
while val<>0
val = Textwindow.Read()
i=i+1
value[i]=val
endwhile
value[i] = "" ' to remove the last value 0
Then you can enter many numbers, and when you enter a 0 the program continues after the endwhile.
Jan [ WhTurner ] The Netherlands
where do i put this if i put the count of numbers in to the menu directly? would this be a sub? I had something like it in my example but not sure how i make it work for my new one. is this an array? and if it is what do i do for the array name? 
The flow of your program should be:
1. enter or read a number of values (my last eexample.)
2. use getitemcount to know the number of values
3. calculate the sum for these values
4. calculate the average.
I hope you can do it with these examples , because I am going offline now. Tomorrow I will be back.
Jan [ WhTurner ] The Netherlands
 Marked as answer by litdevModerator Friday, November 13, 2015 8:35 PM