TI-89 HomeGames ArchiveTitanium GamesGames How ToProgramsFAQForumTI-89 WikiLinks

how to access individual list items from function parameter

 
Post new topic   Reply to topic    Your TI-89 Resource Forum Index -> BASIC Programming
Author Message
TripleDuck



Joined: 10 Sep 2008
Posts: 2

PostPosted: September 10, 2008 12:18 PM    Post subject: how to access individual list items from function parameter Reply with quote

I'm writing a program/function and want to pass in a list, like:

Code:
myfunc([1,-8,3.4])


In the program/function, how do I access each individual element? Supposing I want to return the value of all three numbers multiplied by each other?

I've tried using standard programming access with square brackets and it didn't work..

Code:
(list)
Prgm
list[0]*list[1]*list[2]->mymult
EndPrgm


I've also tried using curly brackets and parentheses. None of these work. So, how do I access the individual elements?

Also, is there a way to obtain a count of the number of items in the list, so the program could do this for any number of items?
Back to top
View user's profile Send private message
calc0002



Joined: 01 Oct 2008
Posts: 4

PostPosted: October 3, 2008 9:29 AM    Post subject: Lists Reply with quote

Code:
(list)
Prgm
list[0]*list[1]*list[2]->mymult
EndPrgm


There's only one thing wrong with the code you have there, and that is that lists in TI-BASIC start with the index 1, not 0. So you want:

Code:
(list)
Prgm
list[1]*list[2]*list[3]->mymult
EndPrgm


If you want to have an unlimited number of elements, use the built in dim() function:

Code:
(list)
Prgm
Local i,prod
1->prod
For i,1,dim(list)
prod*list[i]->prod
EndFor
EndPrgm
Back to top
View user's profile Send private message
Display posts from previous:    View previous topic : View next topic  
Post new topic   Reply to topic    Your TI-89 Resource Forum Index -> BASIC Programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Contact Us | Privacy Policy | Disclaimer | Trademarks

Copyright ©2006 All rights reserved.


Free Greeting Cards | Girly Myspace Layouts | Myspace Unblocker |