### function return problem

My program asks for a value then returns a hailstone sequence for each value 1 to n and counts how many numbers are contained in each sequence, then returns the longest sequence and what number had it. I am having a problem with the return of `int nextNumberInSequence () `
I need it to return two values, which I can then output in my `main` function. I missed that class, and now am rather lost.I can split the function that gives me the number with longest sequence and the sequence lenght into two but all I can think of is copying the function and having each return the needed values.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include #include #include using namespace std; int getUserInputValue () { int n; cout << "Please enter a value: "; cin >> n; return n; } int nextNumberInSequence () { int maxLength, maxNumber; int nextNumber = getUserInputValue (); for (int i = 1; i <= nextNumber; i++ ) { int j = i; int count = 0; while (j > 5) { if (j % 2 != 0) j = 3 * j +1; else j = j / 2; count++; } if (i == 1 || maxLength < count) { maxLength = count; maxNumber = i; } } return maxLength; return maxNumber; } int main () { int maxLength, maxNumber; maxLength = nextNumberInSequence (); cout << "The value with the longest sequence is: " << endl; cout << "The sequence length for " << " is " << maxLength << endl; return 0; }``````
Last edited on
pass the two variables as reference and assign the values to them in the function instead of returning them.

Topic archived. No new replies allowed.