0

I've been struggling with this one for the last day or so. I am only a little over a month into my C++ journey so trying to just understand any and all good quality options to answer my issue.

The issue: To give a little more context, I have setup a function to find the max value and the index of this max value within a 26 character array, assigning both of these results as their own separate variables. This is to be then passed to the main function where the results can be outputted to the console in 2 separate "cout" statements.

I am able to return only one variable, it seems.

As I'm new, I'm all ears for anyone that wants to laugh at me or even give a little advice.

What I have tried so far (with help from other stackoverflow questions) : I have tried to assign both variables to a 2 element array, then returning the array, instead of returning both variables comma-separated. However, it only returned the first element of array.

Using answers from other stackoverflow questions that have been answered, I have tried using pairing statements and using structs but was messy and didn't return my expected results anyways as functions like tuple are not supported on my University version of c++ :/

Stuub
  • 9
  • 4
  • You can return a `std::pair` ... If you're having trouble with that, then post the code you attempted. – ChrisMM Nov 28 '22 at 12:52
  • 1
    Your university should really be upgrading it's version of C++. `std::tuple` has been in C++ since C++11. If you cannot use C++11 then really you are learning a different language. – john Nov 28 '22 at 12:56
  • But even without `std::tuple` you can just declare a struct that holds the values you want to return, – john Nov 28 '22 at 12:57
  • Yes you can return a struct. IMO this is better then a pair or a tuple since you can give meaningfull names the members. e.g. `struct max_info { int max_calue; std::size_t max_value_index; };`. And then return that struct from your function . With pair you always end up with meaningless first and second members. – Pepijn Kramer Nov 28 '22 at 12:58
  • If your university still has such an old compiler (don't tell me its borland C++ from the mid 90's), why not use online compiler/debuggers like https://www.onlinegdb.com/online_c++_compiler# instead? – Pepijn Kramer Nov 28 '22 at 13:00
  • Either return a struct or add two extra parameters by reference that will be modified by the function (and no return needed). – Fareanor Nov 28 '22 at 13:18
  • *... tuple are not supported on my University version of c++* Why are they bothering to teach such an antiquated version of **C++**? – Eljay Nov 28 '22 at 14:14

0 Answers0