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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
#include <fstream>

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.