returning multiple variables from functions

What I'm trying to do is return int, int, string variables from one function back to main and then use those variable initialization in another function. In one of the functions its the input function asking the user what month, the day in the month, and then another variable thats an int.

is there a way to return the values back to main where the values will be set in 3 different variables?

In example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main
{
string month = "";
int date = 0;
int numericalDate = 0;

numericalDate = dataProcessing(menuOption, dailySales, DAYSINYEAR, date, month);
}

int dataProcessing(int menuOption, double dailySales[], int DAYSINYEAR, int date, string month)
{
....

return dayDate;
}


That code just returns the one value but how would I get it to return the vaues for month and date?
Last edited on
You would need to use pass-by-reference (int &a, int &b, etc...). You wouldn't necessarily be "returning" them, but the variables would be updated back to main by the time the function ends.
A function can only return one thing, so if you want to change multiple things you will need to pass by reference like CS Student said above. If you do that, when a change is made to that variable in the function, it changes the variable in main as well.
Topic archived. No new replies allowed.