Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning values

 
Graham Robinson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have it so it will return 1 value, but if i need to take it more than one value in my class how would i do it?

The example here should take the grades of 4 students, to find the average but i don't know how to take it more than one, here's some code.



this is link to a file called marks, where the grades of four students are entered using an array.

Cheers.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not clear about your question.

If you are asking if you can return more than one value from a method, you can't.

If you want multiple values from a method, you should encapsulate them in a class definition and return an instance of that class.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your English is difficult to understand (perhaps you could get someone who speaks better English to write your post) but I think you are asking how to find the average grade of a group of students. An instance of StudentV2 represents *one* student, so I don't think it makes sense for such an object to know the average of four students. You could define a class, say StudentCohort, that holds a collection of students. If you ask a cohort for its average, it will find that out by asking each individual for its grade, then doing the math.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic