0

I'm using an array from another function and I'm trying to have this function return the highest number in the array and the array index associated with it.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285

2 Answers2

1

You can make a struct with two fields, or return an array of length 2. The struct idea is cleaner but a hair more work.

MattPutnam
  • 2,927
  • 2
  • 17
  • 23
0

That's the problem with object-oriented programming, you have to create objects in order to get more than one thing from a function :D

However, if you get the index of the array back from the function, perhaps you can use it to retrieve the actual number?

(Sorry this isn't a comment, I don't have the rep)

DaaaahWhoosh
  • 369
  • 1
  • 4
  • 15
  • This has nothing to do with object orientation, and everything to do with the type system of the language. Even in functional languages that "return multiple values," they're still just returning a structure that holds those values (a tuple). There is nothing about functional programming that requires the existence of a tuple type (though I can't think of any that lack it), and nothing about OO languages that precludes it (Scala and C# both have tuple-types, in fact). – Ian McLaird Oct 16 '14 at 22:01